asp.net MVC Form Post w/ Errors renders view with strong tags surrounding content
I'm at my wits' end with this one. In my MVC app I have simple view, layout and controller logic (returning same view w/ model) when ModelState.IsValid is false. If the form actually submits due to it passing the unobtrusive js logic, the view is returned with <strong> tags surrounding seemingly arbitrary chunks of html.
I have chased this strong tag and can not find any reference to it in any of my views, layouts or extension code. I am not using third party libraries, this is all home grown (sans the MVC.NET part).
I realize this isn't much to go on, but I'm more looking to see if this is a known behavior and I'm just being stupid or if I made a config change somewhere that causes MVC to render with <strong> tags around chunks of html.
As an illustration this is what I'm seeing:
My source layout code looks like
<div id="main">
<h2>@ViewBag.PageTitle</h2>
@Html.Partial( "notices" )
<div class="ajax-notice"></div>
@RenderBody()
</div>
After a post is submitted and returned with errors the rendered source looks like
<div id="main">
<h2>Page Title</h2>
<div class="error">
<strong>
Oops! An error!
</strong>
</div>
<strong>
<div class="ajax-notice"></div>
</strong>
@RenderBody()
</div>
The <strong> tag in bot the error classed div and surrounding the ajax-notice classed div are not in the source code.
notice Partial looks like:
<div class="error">@Html.ValidationSummary</div>开发者_高级运维;
Finally I am simply returning to the same view with Controller logic like such:
public ActionResult Create( User model ){
if( !ModelState.IsValid ){
return( View ( "new", model ) );
}
}
Here are few things to try
@Html.ValidationSummary will create a div for you with a ul tag containg all of the errors.
The output should look something like this by default:
<div class="validation-summary-errors">
<ul>
<li>Username is invalid</li>
</ul>
</div>
I would first try taking the @Html.ValidationSummary out of the partialview and just render it in the regular view. Modify your CSS to use validation-summary-errors instead of just errors as the class.
I am not sure the exact purpose for having your @Html.ValidationSummarry in a partial view anyway.
精彩评论