我有將點擊ajax.actionlink後返還,下面的部分觀點: -客戶端數據標註不工作對containe ajax.beginform我的asp.net mvc的內部的局部視圖
@model System.Models.Answer
@{
ViewBag.Title = "Create";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<div id = "partialWrapper">
@using (Ajax.BeginForm("Create", "Answer", new AjaxOptions
{
HttpMethod = "Post",
InsertionMode = InsertionMode.InsertAfter,
UpdateTargetId = "incrementanswer",
OnSuccess = "removePartial"
}))
{
<div id = "returnedquestion">
@Html.ValidationSummary(true)
<fieldset>
<legend>Answer here</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.IsRight)
</div>
<div class="editor-field">
@Html.DropDownList("IsRight", String.Empty)
@Html.ValidationMessageFor(model => model.IsRight)
</div>
</fieldset>
<input type= "hidden" name = "questionid" value = @ViewBag.questionid>
<input type= "hidden" name = "assessmentid" value = @ViewBag.assessmentid>
<input type="submit" value="Add answer" />
</div>
}
</div>
問題是,如果我點擊提交按鈕,同時離開所需的文件空白,那麼將不會顯示客戶端驗證IsRight和描述字段是必需的,而是整個視圖(包含佈局)將被返回,那麼可能是什麼問題?
這裏是正在從partila視圖稱爲操作方法: -
[HttpPost]
public ActionResult Create(int questionid, Answer a)
{
if (ModelState.IsValid)
{
repository.AddAnswer(a);
repository.Save();
return PartialView("_details",a);
}
return View(a);
和ajax.actionlink,將返回的局部視圖: -
<div id ="link">
@Ajax.ActionLink("Add New Answer", "Create", "Answer",
new { questionid = Model.QuestionID },
new AjaxOptions
{
HttpMethod = "Get",
UpdateTargetId = "link",
InsertionMode = InsertionMode.InsertAfter,
LoadingElementId = "progress"
})
</div>
是的,我可以看到所有這些腳本在腳本文檔部分下被成功解僱後,我運行應用程序,我也將Jquery.validate腳本移動到部分視圖,而不是在主視圖和問題沒有解決。 – 2012-03-05 22:23:17