2つの送信アクションでビューMyView.chstmlをセットアップしましたが、「シリアル化中に循環参照が検出されましたタイプ 'System.Reflection.RuntimeModule'のオブジェクトです。簡単にトラブルシューティングを行うには?理由を見つける方法 "シリアライズ中に循環参照が検出されました...." System.Reflection.RuntimeModule '
@using (Html.BeginForm("MyView", "Worker", FormMethod.Post, new { enctype = "multipart/form-data", @name = "formWorker" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal" id="divWork"> ....
<div class="form-group">
<button id="btnSubmit" class="btn btn-success" type="submit" value="Work1">Work1</button>
</div>
<div id="Dynamictable" class="table-responsive hidden" name="dtable">
<table class="table table-bordered" id="dctable" name="dctable"></table>
</div>
<div id="dialogsubmit" title="second submit">
<div id="dialog-content" name="dialog-content" class="form-control hidden"> </div>
</div>
</div>
、スクリプトで
(function() {
//strangely the below ajax is never called
$('#formWorker').submit(function() {
debugger;
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function (result) {
debugger;
bootbox.alert(result);
}
});
// it is important to return false in order to
// cancel the default submission of the form
// and perform the AJAX call
return false;
});
}
$("#btnSubmit").click(function() {
if(document.getElementById('dctable').getElementsByTagName("tr").length < 1)
{
aRow = document.all("dctable").insertRow();
var oCell = aRow.insertCell();
oCell = newRow.insertCell();
oCell.innerHTML = '<input type="submit" name="submit2" value="submit2" />';
**//strangely if i replace the above RHS with below, it act as submit halft submit form (half becuase the FormCollection object in HttpPost method of controller lacks key submit2 and also HttpPostedFileBase object came as null in controller method ,**
*//'<button id="submit2" name="submit2" class="btn submit2" value="submit2" ><i class="fa fa-search"></i> submit2</button>'*
return false;
}
});
</script>
コントローラで
[HttpGet]
public ActionResult Worker()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Worker(HttpPostedFileBase file, FormCollection form)
{
string value = form["submit2"]; //half submit form as it is null in additon to file is null. if i use commented RHS , all good here, but no option in view to process the output in same view.
IEnumerable<object> data = Enumerable.Empty<object>();
if (value != null) // key doesn't exist
{
//process here and and return json to shown result on same page using popup/alert.
return this.Json(
new
{
Result = data.ToList()
}, JsonRequestBehavior.AllowGet
);
}
return PartialView("anoterhView", data.ToList());
}