tags:

views:

27

answers:

1

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 update the dialog with the error messages

Please, I need an example how to do that?

A: 

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)
}
James
Thanks, How to display the errors isn`t my question. My question is how to send the partial view values to the controller, such that the error messages returned by the controller are updated to the partial view.
Look at the `Validate` method I have written. In the `RenderPartial` method you can pass in the model. Every view page is passed in a generic type `TModel`, in this case I have set my model to be a collection of strings (*see the top of Dialog.ascx*) and I am passing this in via the RenderPartial method.
James