ASP.NET MVC Interview Questions and Answers (162) - Page 6

In Asp.Net MVC, the Entity framework approach to write the c# classes and use those class definitions to create the database ?

NOTE: This is objective type question, Please click question title for correct answer.
In Asp.Net MVC, the Html helper used for creating a label in Razor view is ?

NOTE: This is objective type question, Please click question title for correct answer.
In Asp.Net MVC, the Attribute used to prevent the Cross-Site Request Forgery is ?

NOTE: This is objective type question, Please click question title for correct answer.
What is the difference between Url.RouteUrl and Url.HttpRouteUrl?

Url.RouteUrl is used to generate a fully qualified URL for specified route values by using a route name configured in App_Start/RouteConfig.cs file.

@Url.RouteUrl("MyCustomRoute", new { action = "New", id = 12, Name = "Sheo" })
gives output as /CustomController/New/12?Name=Sheo


Url.HttpRouteUrl is also used to generate fully qualified URL for the specified route values but for Web API Routes. Internally this method add an "httproute" entry to routeValues. GetVirtualPath method of the Web Api route classes return null unless we include "httproute" in the values.
@Url.HttpRouteUrl("MyCustomRoute", new { action = "New", id = 12, Name = "Sheo" })</p>
gives output as /CustomController/New/12?Name=Sheo&httproute=True.

Notice httproute query-string at the end.
In MVC is mandatory to be Map route {controller}/{action}/{id} In This format only..??

Its not mandatory to be URL string must be in controller/action/params format.

If User defined in his RouteConfig file like {controller}/{action}/{id} Query string will be controller/action/id.

if user defined in his RouteConfig file like {action}/{controller}/{id} Query string will be
Action/controlleer/id.
What is the difference between Html.EditorFor and Html.TextBoxFor in ASP.NET MVC?

Html.EditorFor

@Html.EditorFor(model => model.LastName)

This HTML helper method is very dynamic in nature. Based on which type of data is passed to this method, the output changes.

For example,
1. if model property type is of string type, it renders a textbox
2. if the property type is boolean type it renders a checkbox.
3. if the property type is of integer type, it render input type="number" textbox.

In order to control the output of the Html.EditorFor we can use EditorTemplates for different data types.

Html.TextBoxFor

@Html.TextBoxFor(model => model.LastName)

This HTML helper method only renders a TextBox as output irrespective of whatever data type the model property is of.
Can we have View State in MVC?

No,we do not have ViewState concept in Asp.Net MVC that is used for storing or persisting the values of controls in the current page.
So,Asp.Net MVC pages are very Lightweighted and our request and response times becomes much faster.
Tell us Alternative to View State in MVC.

1. For retaining the values during postback in the MVC page values we can use Ajax,so that values in the control will never be clear.
2. For temporarily storing the value in current and the subsequent requests,we can use TempData concept.
How to prevent a browser from calling an action method of MVC?

NOTE: This is objective type question, Please click question title for correct answer.
How to know whether a request is a child request in normal action method of controller?

NOTE: This is objective type question, Please click question title for correct answer.
How to render a optional section in the _Layout page

NOTE: This is objective type question, Please click question title for correct answer.
How to check if a particular section in defined in the view page?

NOTE: This is objective type question, Please click question title for correct answer.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories