ValidationSummary() not displaying when using RenderPartial in View
asp.net, asp.net-mvc, asp.net-mvc-3, asp.net-mvc-4, razor
Solution
Unfortunately, this cannot work. A Partial is just a string.
While RenderPartial actually 'writes' the partial markup rather than sending a string back to the View Generator, it does not rebind your View to a new model. If you want Validation Summary to work it must be bound to a model in your main View.
Problem
When I use ``` @{Html.RenderPartial("Login");} ``` inside my main view, the `@Html.ValidationSummary()` doesn't work, but when I copy the code from "Login" inside main view, it works. Why is that, and how do I display validation messages from the partial view? Here is partial view "Login": ``` @model NyNo.Models.LoginModel @using (Html.BeginForm()) { <fieldset> @Html.AntiForgeryToken() @Html.ValidationSummary(true) @Html.TextBoxFor(m => m.UserName, new { @placeholder = "Username" }) @Html.ValidationMessageFor(m => m.UserName) @Html.PasswordFor(m => m.Password, new { @placeholder = "Password" }) @Html.ValidationMessageFor(m => m.Password) @Html.CheckBoxFor(m => m.RememberMe) @Html.LabelFor(m => m.RememberMe, new { @class = "checkbox" }) <input type="submit" class="button" value="Log in" /> </fieldset> } @section Scripts { @Scripts.Render("~/bundles/jqueryval") } ``` Hope you understand, thanks!