jquery UI 대화 상자에서 ajax 요청을 사용할 때 clienside 유효성 검사를 실행하려고합니다.jquery.validate.unobtrusive인가요?
이것은 제출 버튼이없고 다시 게시하지 않음을 의미합니다. 왜 내가 그걸 작동시키지 못했는지 알 수가 없었다.
게시했습니다. this question입니다. 내가 결론을 내릴 수있는 이유는 무엇이든간에 내 부분보기와 함께 jquery.validate.unobtrusive를로드해야한다는 것입니다. 나에게 의미가 없다.
이것은 버그입니까?
나는 또한 사라와 이에 대한 추가 혜택은 당신이 원하는 경우에 당신은 단지 내 작은 샘플 응용 프로그램을 다운로드하고 그것을 밖으로 시도 할 수 있다는 것입니다 asp.net codeplex
에 오류를 기록
편집.
또는 당신은
가 비어 있지 않은 asp.net의 MVC 3 응용 프로그램 (I 면도기를 사용하고 있습니다)
_Layout.cshtml
을 확인 다음 단계를 수행 할 수 @ ViewBag.Title
<script type="text/javascript"> $(function() { $.get('/home/dialog', null, function (r) { var a = $("#dialog").dialog({ resizable: false, height: 500, modal: true, buttons: { "Delete all items": function() { $('#testFrm').validate().form(); }, Cancel: function() { $(this).dialog("close"); } } }).html(r); }); $('#testFrm').live('submit',function (e) { e.preventDefault(); }); }); </script> </head> <body> <div class="page"> <div id="header"> <div id="title"> <h1>My MVC Application</h1> </div> <div id="logindisplay"> @Html.Partial("_LogOnPartial") </div> <div id="menucontainer"> <ul id="menu"> <li>@Html.ActionLink("Home", "Index", "Home")</li> <li>@Html.ActionLink("About", "About", "Home")</li> </ul> </div> </div> <div id="main"> @RenderBody() <div id="footer"> </div> </div> </div> </body> </html>
ViewUserControl1 (부분보기) - 스틱 홈보기 폴더@model MvcApplication1.Models.TestModel
@using (Html.BeginForm ("테스트", "계정에 ", FormMethod.Post, new {@ id ="testFrm "})) { @ Html.ValidationSummary() @ Html.TextBoxFor (x => x.Name) }
지수
@model MvcApplication1.Models.TestModel
@{
ViewBag.Title = "Home Page";
}
<h2>@ViewBag.Message</h2>
<p>
To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
</p>
@DateTime.Now
<div id="dialog">
</div>
참고 부분보기의 아약스 요청이
홈 컨트롤러 저장됩니다이 될 것입니다 대화 ID (이로 교체 존재한다)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplication1.Controllers
{
public class HomeController : Controller
{
public ActionResult test()
{
return null;
}
public PartialViewResult Dialog()
{
return PartialView("ViewUserControl1");
}
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View();
}
public ActionResult About()
{
return View();
}
}
}
TestModel.cs // 뷰 모델
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;
namespace MvcApplication1.Models
{
public class TestModel
{
[Required()]
public string Name { get; set; }
}
}
웹.config
<appSettings>
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
이제 응용 프로그램을 실행하십시오. "모든 항목 삭제"및 "쿼리 제출"을 클릭하십시오.
아무 것도 일어나지 않아야합니다. 나를 위해 유효성 검사가 표시되지 않습니다.
지금 가서
<script src="../../Scripts/jquery.validate.unobtrusive.js" type="text/javascript"></script>
@model MvcApplication1.Models.TestModel
@using (Html.BeginForm("test","Account",FormMethod.Post,new {@id="testFrm"}))
{
@Html.ValidationSummary()
@Html.TextBoxFor(x => x.Name)
<input type="submit" />
}
지금 다시 시도 부분보기 (ViewUserControl1)에 다음 행을 추가합니다.
이제 유효성 검사 오류가 발생합니다.