Home Interview Questions and Answers MVC Interview Questions and Answers For Graduates Part-4

MVC-Diagram31.How to change the action name in ASP.Net MVC?
“ActionName” attribute can be used for changing the action name. Below is the sample code snippet to demonstrate more :

public ActionResult TestAction()
return View();
} So in the above code snippet “TestAction” is the original action name and in “ActionName” attribute, name – “TestActionNew” is given. So the caller of this action method will use the name “TestActionNew” to call this action.

32.What are Code Blocks in Views?
Unlike code expressions that are evaluated and sent to the response, it is the blocks of code that are executed. This is useful for declaring variables which we may be required to be used later.

int x = 123;
string y = “aa”;

33.What is the “HelperPage.IsAjax” Property?
The HelperPage.IsAjax property gets a value that indicates whether Ajax is being used during the request of the Web page.

34.How we can call a JavaScript function on the change of a Dropdown List in ASP.Net MVC?
Create a JavaScript method:

function DrpIndexChanged() { } Invoke the method:
< %:Html.DropDownListFor(x => x.SelectedProduct, new SelectList(Model.Customers, “Value”, “Text”), “Please Select a Customer”, new { id = “ddlCustomers”, onchange=” DrpIndexChanged ()” })%>

35.What are Validation Annotations?
Data annotations are attributes which can be found in the “System.ComponentModel.DataAnnotations” namespace. These attributes will be used for server-side validation and client-side validation is also supported. Four attributes – Required, String Length, Regular Expression and Range are used to cover the common validation scenarios.

36.Why to use Html.Partial in ASP.Net MVC?
This method is used to render the specified partial view as an HTML string. This method does not depend on any action methods. We can use this like below : @Html.Partial(“TestPartialView”)

37.What is Html.RenderPartial?
Result of the method : “RenderPartial” is directly written to the HTML response. This method does not return anything (void). This method also does not depend on action methods. RenderPartial() method calls “Write()” internally and we have to make sure that “RenderPartial” method is enclosed in the bracket. Below is the sample code snippet : @{Html.RenderPartial(“TestPartialView”); }

38.What is RouteConfig.cs in ASP.Net MVC 4?
“RouteConfig.cs” holds the routing configuration for ASP.Net MVC. RouteConfig will be initialized on Application_Start event registered in Global.asax.

39.What are Scaffold templates in ASP.Net MVC?
Scaffolding in ASP.NET ASP.Net MVC is used to generate the Controllers,Model and Views for create, read, update, and delete (CRUD) functionality in an application. The scaffolding will be knowing the naming conventions used for models and controllers and views.

40.Explain the types of Scaffoldings.
Below are the types of scaffoldings :


You may also like

Leave a Comment