MVC HTML.Form vs Ajax.Form

  • Postback – HTML.BeginForm renders a Form tag which makes a complete postback to the server on submit. In the other hand Ajax.BeginForm renders a form tag which will make an asynchronous request to server.
  • Rendering -Html.BeginForm leads to complete page refresh whereas Ajax.BeginForm leads to only part of the page update.
  • How page updates –

  • Ajax.BeginForm relies on JavaScript to get part of the page update. Client (who develop the page) will write some JavaScript code which will get executed on completing of asynchronous request. That JavaScript will be responsible for updating of partial content in page.
  • In case of Html.BeginForm entire page get replaced with returned response.

Syntax

 

Html.BeginForm

 

@using (Html.BeginForm(“MyActuinMethod”, “MyPostController”, FormMethod.Post))

{

<inputtype=”submit”name=”BtnButton”value=”Click To Sbumit”/>

}

 

Ajax.BeginForm

 

@using (Ajax.BeginForm(“MyActionMethod”, “Home”, newAjaxOptions() {OnSuccess=”MySuccessFunction” }))

{

<inputtype=”submit”name=”BtnButton”value=”Click To Sbumit”/>

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s