Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.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
Asp.net mvc 模型无效,返回不带主视图的局部视图_Asp.net Mvc - Fatal编程技术网

Asp.net mvc 模型无效,返回不带主视图的局部视图

Asp.net mvc 模型无效,返回不带主视图的局部视图,asp.net-mvc,Asp.net Mvc,在我的EspaceClient/Compte.cshtml中,我检索到一个局部视图。 它可以工作,但是当ModelState无效时,我只检索部分视图,而不检索主视图 多谢各位 function partialCoordonnees() { $.ajax({ url: '/Utilisateurs/Edit/'+ @Model.Id, dataType: "html", success: function (data) {

在我的EspaceClient/Compte.cshtml中,我检索到一个局部视图。 它可以工作,但是当ModelState无效时,我只检索部分视图,而不检索主视图

多谢各位

function partialCoordonnees() {
        $.ajax({
        url: '/Utilisateurs/Edit/'+ @Model.Id,
        dataType: "html",
        success: function (data) {
         $('.fifth').html(data);
        }
        });
};
在我的控制器中

public ActionResult Edit(int? id)
{
     Utilisateur utilisateur = db.Utilisateurs.Find(id);
     return PartialView("_CoordonneesCompte", utilisateur);
}


public ActionResult Edit(Utilisateur utilisateur)
{
    if (ModelState.IsValid)
    {
        db.Entry(utilisateur).State = EntityState.Modified;
        db.SaveChanges();
        return RedirectToAction("Index", "EspaceClient", new { id=utilisateur.Id  });
    }
        return PartialView("_CoordonneesCompte", utilisateur);
}

不要使用ModelState.IsValid执行服务器端验证

使用非结构化jQuery库进行客户端验证

在cshtml中添加jquery.unobtrusiveajax.min.jsjquery.validate.min.js

[示例]

//this code goes in your partialview
$(function(){ 
  //allow the validation framework to re-prase the DOM
  jQuery.validator.unobtrusive.parse(); 

  //or to give the parser some context, supply it with a selector
  //jQuery validator will parse all child elements (deep) starting
  //from the selector element supplied
  jQuery.validator.unobtrusive.parse("#formId");
});


//then in your parent page handle the form submission
$(function(){
  $("#SubmitButton").click(function(){ 
    if (!$("#Form1").valid()){ 
      return false; 
    } 
  });
});
这个例子的形式


希望它能帮助您……

检查呈现的HTML——它可能是插入到目标元素中的完整页面。AJAX不会遵循重定向请求。如果需要重定向,则需要检查302重定向的响应,并在回调中使用javascript进行导航;当模型无效时,此返回部分视图(“u CoordonnesCompte”,Usilizateur)中存在问题。我不知道我该怎么做你说的