1

In my code I am using a partial view (call it PV1)

<div id="div_1">
    <% Html.Partial("PV1", Model); %>
</div>

and in that partial view I am using "Ajax.BeginForm" to redirect it to a particular action, hence it is doing so ...

using (Ajax.BeginForm("action1", "Forms", null, new AjaxOptions { UpdateTargetId = "div_1" }, new { id = "form1" }))
                {
                    Response.write("I am here.");
                }

public ActionResult action1(XYZ Model)
{
        //
       return PartialView("PV1", Model);
}

at the last line of action I am again calling the same partial 'PV1', hence it is doing this too ...

but when rendering the view it don't print or do the steps written with in partial view, it override them with and show nothing ...

2 Answers 2

2

Html.Partial actually returns the result of rendering the view, you want to do <%= Html.Partial() %> or <% Html.RenderPartial(); %>

Html.Partial() returns the Html and thusly must be output on the page via <%= %> and Html.RenderPartial() uses Response.Write to output onto the page and can be used with <% %>.

Sign up to request clarification or add additional context in comments.

2 Comments

I am using Html.Partial(), as I am returning the output result from controller action to a view ... but does it make any difference to my query what I am using to render the output ... and just to let you know ... tried both method ... but problems still exist ... pls provide me with an example ...
I did it using Html.RenderPartial() ... but doing so you have to be very careful arranging your divs ...
1

This is not what you would use Ajax.BeginForm for. That helper is used to create actual <form> tags that will later be submitted to the server using MVC's unobtrusive ajax (so you still need some kind of a trigger action - a button, javascript - anything that submits the form).

I'm am not very clear on what you're trying to achieve. If you want to load a partial view with ajax, I would suggest using something like jQuery's ajax load method.

1 Comment

i am using a submit button ... but again instead rendering the partial view with in page it displays the partial view in blank page ... I also tried to used InsertionMode with Ajax.BeginForm ( ... ) and ... i am trying to achieve same result as it is explained in following post stackoverflow.com/questions/931001/… but the result is same ... and can you pls also help me show how to achieve the same behaviour using jquery & ajax (pls give some code example ...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.