私の jquery では、Post アクションを呼び出すことができます。ここでの問題は、ModelState.IsValid が true を返し、部分ビューが jquery.dialog 内に読み込まれる場合です。どうすればいいですか?過去4日間から苦労しています。助けてください。
これが私のコードです。私は以下のようにポストアクションを持っています:
[HttpPost]
public ActionResult Add(MyModel mj)
{
if (ModelState.IsValid)
{
mj.Id = mj.ModifyJob();
}
else
{
return new JsonResult() { Data = "error" };
}
return View(mj);
}
Jquery は次のとおりです。
<script type="text/javascript">
$(function () {
$('#new-value-link').click(function () {
$.post('<%: Url.Action("Add","MyController") %>',
$('#addform').serialize(),
function (data) {
success(data);
});
return false;
});
});
function success(data) {
if (data != "error") {
var href = this.href;
$('#dialog').dialog({
modal: true,
height: 700,
width: 900,
open: function (event, ui) {
$(this).load(href, function (result) {
$('#Preview-form').submit(function () {
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function (json) {
$('#dialog').dialog('close');
window.location = json.redirectTo;
}
});
return false;
});
});
}
});
}
else {
alert('hi');
}
return;
}