?
Solved

MVC3, Ajax, Posting back just a single Controller Action

Posted on 2011-10-15
3
Medium Priority
?
388 Views
Last Modified: 2012-05-12
I am new to using Ajax with MVC3 and wanted to really understand how it worked better. I worked on a project where they were using Unobtrusive validation, jqGrid and Ajax. I see how to configure the DataDash attributes such as:

data-val-remote-url='/Ajax/MyControllerAction
data-val-remote-additionalfields=MyValue'

Then when the jqGrid determines it is time to call MyControllerAction, it does so with the correct parameters. So it all works but my question involves the performance of this call.

When there is not Ajax used, an MVC post for any controller action requires a full page post. Right? And what about using a property of the Model inside the View using the following C# syntax? In this case the property name is MyType.

 @if (Model.MyType == MyTypes.Pressure)
       <text>
                      // insert script here
        </text>
  }
  else
 {
        <text>
                      // insert script here
        </text>
 }

Is this used like a variable? I am curious. Anything you can also mention relating tol Ajax, its asynchronous nature, etc. I would appreciate as I am new to using Ajax with MVC.

Thanks.
0
Comment
Question by:newbieweb
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
strickdd earned 1500 total points
ID: 36980136
On a view, when you reference code like this:

Model.MyType == MyTypes.Pressure

It is compiled and run server-side before being served to the client. Therefore it is handled during a post/get request and doesn't require a separate call to the server. It is identical to the concept of the old Classic ASP <%= %> tags.
0
 

Author Comment

by:newbieweb
ID: 36982991
I know its the same as the old Classic ASP <%= %> tags. But I wonder how it relates to an Ajax POST request.

Does the whole page post back as a result of this call?

 @if (Model.MyType == MyTypes.Pressure)



Thanks.


0
 

Author Closing Comment

by:newbieweb
ID: 36989563
Thanks.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question