views:

42

answers:

1

I have a ASP.NET MVC 2 webpage in which I render multiple PartialViews of the same type. Each partial view contains a Ajax-form for posting smth. The form consists of:

  • an input: EditorFor(m => m.content)
  • the validation for the input: ValidationMessageFor(m => m.Content)

The problem is that because there are more than 1 of these forms on the page there is a conflict in the names of the input fields. This I can solve by adding the 'htmlFieldName' property of the EditorFor() overload, but it causes another problem; the validation doesn't work anymore because the name of the input field changed...

Any ideas?

A: 

Ok, I solved it. The thing is that the conflict wasn't because of the ids of the input field, but of the validation field. So now it works like this:

<%= Html.EditorFor(m => m.Content)%>
<%= Html.ValidationMessageFor(
         m => m.Content, 
         null, 
         new { id = Model.ValidationMessageId, name = Model.ValidationMessageId })%>

where ValidationMessageId is a readonly string property of the model which returns an unique html id for the validation field.

nogola