1
我面臨我的asp.net mvc3應用程序內部的一般問題,即所有局部視圖都不會顯示我使用數據註釋定義的客戶端驗證錯誤 ,, for例如我已經定義了以下數據的註解: -客戶端數據註解不適用於局部視圖
public class Country_Validation
{
[Required(ErrorMessage="{0} is required.")]
[StringLength(30, ErrorMessage="{0} is too long.",MinimumLength=1)]
public string Description { get; set; }
}
和我有以下動作的方法將使用ajax.beginform
被調用,這將隨後返回的局部視圖來創建新Country
對象: -
public ActionResult Create()
{
Country c = new Country();
return PartialView("_Create",c);
}
這將返回以下_Create
局部視圖: -
@model Medical.Models.Country
<div id = "partialWrapper">
@using (Ajax.BeginForm("Create", "Country", new AjaxOptions
{
HttpMethod = "Post",
InsertionMode = InsertionMode.InsertBefore,
UpdateTargetId = "Countrytable",
OnSuccess = "clearform"
}))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Country</legend>
<div class="editor-label">
<strong>Country Name:-</strong>
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
<input type="submit" value="Create" />
</fieldset>
}
</div>
但如果我嘗試同時留下Description
字段爲空以添加新country
對象,然後將顯示沒有客戶端驗證錯誤,而如果我返回一個常規的視圖(不是部分),那麼所有的客戶端驗證錯誤將正常工作? 那麼可能是什麼問題? BR
我回到了這個問題,但增加iewContext.FormContext =新FormContext();不管用。 – 2014-01-15 14:00:27