Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将验证错误返回到MVC 3中的jQuery对话框_Jquery_Asp.net_Asp.net Mvc 3_Jquery Validate - Fatal编程技术网

将验证错误返回到MVC 3中的jQuery对话框

将验证错误返回到MVC 3中的jQuery对话框,jquery,asp.net,asp.net-mvc-3,jquery-validate,Jquery,Asp.net,Asp.net Mvc 3,Jquery Validate,如果有一个页面加载jQuery模式对话框,该模式包含一个表单。我如何返回一个错误以使其加载到模式中,如果我返回一个PartialView,则页面仅加载对话框表单内容(该内容仅用于模式中) 这里是风景 <span><a id="end" href="#">Launch End Dialog</a> </span> <div id="end-dialog" class="dialog"> <div id="end-inner

如果有一个页面加载jQuery模式对话框,该模式包含一个表单。我如何返回一个错误以使其加载到模式中,如果我返回一个PartialView,则页面仅加载对话框表单内容(该内容仅用于模式中)

这里是风景

<span><a id="end" href="#">Launch End Dialog</a> </span>



<div id="end-dialog" class="dialog">
  <div id="end-inner"></div>
  <hr />
</div>

<script type="text/javascript">
  $(function () {


    var endDialog = $("#end-care-plan-dialog").dialog({

    });

    $("#end").click(function () {
      endDialog.dialog('close');
    });

    $('#end').click(function () {
      $('#end-inner').load(baseUrl + "/End", $.param({ id: '@Model.id' }),
              function () {
                endDialog.dialog('open');
              });
    });
  });
</script>
注意-jquery.validate和jquery.validate.unstructive被加载到视图中

谢谢,希望这有意义

更新:Diego-这是包含表单的局部视图(加载到moal中)

@使用(Html.BeginForm(c=>c.End(@Model.Id)))
{ @Html.HiddenFor(m=>m.Id) @DropDownListFor(m=>m.EndReasonId,RefData.EndReasons) 其他原因 @EditorFor(m=>m.EndReasonOther) @Html.ValidationMessageFor(m=>m.EndReasonOther) @(Html.ActionLink(c=>c.Edit(@Model.Id),“取消”)@Html.SubmitButton(“结束”,“结束”) }

我在哪里修改你的代码


谢谢

这确实有道理。您只需确保表单是通过AJAX提交的,否则整个页面将刷新。要覆盖默认行为,您需要表单的
submit
事件的处理程序。假设您的表单是
myForm

$('#myForm').submit(function() { // catch the form's submit event
    $.ajax({ 
        data: $(this).serialize(), // get the form data
        type: $(this).attr('method'), // GET or POST
        url: $(this).attr('action'), // the file to call
        success: function(response) { // on success..
            $('#end-inner').html(response); // update the DIV
        }
});
return false; // cancel original event to prevent form submitting
});

您可以使用ajax使其更简单
@using (Html.BeginForm<EndController>(c => c.End(@Model.Id)))
$('#myForm').submit(function() { // catch the form's submit event
    $.ajax({ 
        data: $(this).serialize(), // get the form data
        type: $(this).attr('method'), // GET or POST
        url: $(this).attr('action'), // the file to call
        success: function(response) { // on success..
            $('#end-inner').html(response); // update the DIV
        }
});
return false; // cancel original event to prevent form submitting
});