I am having this issue where I have a form in a partialview but when validating it jumps out of the parent view and appears on its own (having the submit action url).
Also I tried with Render.Action, where validation does not fire at all.
I am using ASP.NET MVC 2 RC and need the server-side validation to work, using the built in validation. Anyone got any suggestions?
Thanks
Code Partial View:
<%=Html.ValidationSummary() %>
<% using (Html.BeginForm("Edit", "Category", FormMethod.Post))
{%>
<fieldset>
<legend>Edit category</legend>
<p>
<label for="CategoryName">Category name:</label>
<%= Html.TextBox("CategoryName", Model.CategoryName)%>
<%= Html.ValidationMessage("CategoryName", "*")%>
</p>
<p class="submit">
<input type="submit" value="Edit" />
<%=Html.AntiForgeryToken()%>
<%= Html.Hidden("CatId", Model.Id)%>
</p>
</fieldset>
<% }
Model Property:
[Required(ErrorMessage="Required")]
public string CategoryName { get; set; }
Edit Action:
[ValidateAntiForgeryToken]
[HttpPost()]
public ActionResult Edit(int catId, CategoryPageViewModel categoryModel)
{
if (ModelState.IsValid)
{
//TODO
}
return View("list", categoryModel);
}