asp.net mvc Ajax.BeginForm clone.

Posted by denis_n on Stack Overflow See other posts from Stack Overflow or by denis_n
Published on 2011-01-17T02:00:19Z Indexed on 2011/01/18 3:53 UTC
Read the original article Hit count: 264

Filed under:
|

Hello,

I'm using asp.net mvc ajax.

The partial view is using Ajax.BeginForm (just an example):

<div id="divPlaceholder">
<% using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "divPlaceholder" })) { %>
     ... asp.net mvc controls and validation messages
     <input type="submit" value="Save" />
<% } %>
</div>

After update, if validation fails, the html is:

<div id="divPlaceholder">
    <div id="divPlaceholder">
    ...form
    </div>
</div>

I don't like that the returned html is inserted, instead it should replace original div.

Probably on POST I should not render <div> around form in partial view or render the div without id.

What else can I do in this situation?

I was thinking that maybe I should write a helper, something like Ajax.DivBeginForm, which will render form inside div on GET and hide the div on POST.

Can somebody provide a good advice how to write such helper (Ajax.DivBeginForm)?

I'd like it to work with using keyword:

<% using (Ajax.DivBeginForm(new AjaxOptions { UpdateTargetId = "myId" })) { ... }%>

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about asp.net-mvc-2