开发者

How to update a partial view which is displayed as a dialog?

开发者 https://www.devze.com 2022-12-29 14:36 出处:网络
How can I update a partial view that is displayed as dialog? I have to send error messages from the controller to the partial view that is displayed as a dialog, i.e in other words I want to upd开发

How can I update a partial view that is displayed as dialog?

I have to send error messages from the controller to the partial view that is displayed as a dialog, i.e in other words I want to upd开发者_高级运维ate the dialog with the error messages

Please, I need an example how to do that?


Not quite sure I understand you fully, if you are just asking how you pass a list of errors to a partial view to display them then here is a simple example:

Dialog.ascx

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<ICollection<string>>" %>
<% if (Model.Count > 0) { %>
<h3>The following errors have occurred:</h3>
<ul>
     <% foreach (var err in Model) { %>
     <li><%= err %></li>
     <% } %>
</ul>
<% } else { %>
<h3>No errors were found</h3>
<% } %>

Controller

public ActionResult Validate()
{
    List<string> errors = new List<string>();
    // validate and build up errors
    return RenderPartial("Dialog", errors)
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号