Asp Dot Net Mvc Interview Questions

1 What are HTML helpers in MVC?

With MVC, HTML helpers are much like traditional ASP.NET Web Form controls.

Just like web form controls in ASP.NET, HTML helpers are used to modify HTML. But HTML helpers are more lightweight. Unlike Web Form controls, an HTML helper does not have an event model and a view state.

In most cases, an HTML helper is just a method that returns a string.

With MVC, you can create your own helpers, or use the built in HTML helpers.

Standard HTML Helpers

HTML Links

The easiest way to render an HTML link in is to use the HTML.ActionLink() helper.With MVC, the Html.ActionLink() does not link to a view. It creates a link to a controller action.

ASP Syntax

The first parameter is the link text, and the second parameter is the name of the controller action.

The Html.ActionLink() helper above, outputs the following HTML:

The Html.ActionLink() helper has several properties:

  • Property Description.
  • .linkText The link text (label).
  • .actionName The target action.
  • .routeValues The values passed to the action.
  • .controllerName The target controller.
  • .htmlAttributes The set of attributes to the link.
  • .protocol The link protocol.
  • .hostname The host name for the link.
  • .fragment The anchor target for the link.
  • HTML Form Elements

    There following HTML helpers can be used to render (modify and output) HTML form elements:

  • BeginForm()
  • EndForm()
  • TextArea()
  • TextBox()
  • CheckBox()
  • RadioButton()
  • ListBox()
  • DropDownList()
  • Hidden()
  • Password()
  • ASP.NET Syntax C#

    Learn more here – HTML Helpers in MVC: Part 1

    1 What are the Main Razor Syntax Rules?


  • Razor code blocks are enclosed in @{ … }
  • Inline expressions (variables and functions) start with @
  • Code statements end with semicolon
  • Variables are declared with the var keyword
  • Strings are enclosed with quotation marks
  • C# code is case sensitive
  • C# files have the extension .cshtml
  • C# Example

    Learn more here – Introduction to Microsoft ASP.NET MVC 3 Razor View Engine

    3 How can we done Custom Error Page in MVC?


    The HandleErrorAttribute allows you to use a custom page for this error. First you need to update your web.config file to allow your application to handle custom errors.

    Then, your action method needs to be marked with the atttribute.

    By calling the ThrowException action, this would then redirect the user to the default error page. In our case though, we want to use a custom error page and redirect the user there instead.So, lets create our new custom view page.

    Next, we simply need to update the HandleErrorAttribute on the action method.

    Learn more here – Custom Error Page in ASP.NET MVC

    Define POST and GET action types.

    POST action type submits data to be processed to a specified resource. We pass the essential URL and data with all the POST requests. It can take up overloads.

    GET action type requests data from a specified resource. We pass the compulsory URLs with all the GET requests. It can take up overloads.Â

    asp dot net mvc interview questions

    Can you tell two instances where routing is not required or implemented?

    We do not require routing when routing is disabled for a URL pattern and when a physical file matching the URL pattern is found.Â

    2 What is Route Constraints in MVC?


    Routing is a great feature of MVC, it provides a REST based URL that is very easy to remember and improves page ranking in search engines.

    This article is not an introduction to Routing in MVC, but we will learn a few features of routing and by implementing them we can develop a very flexible and user-friendly application. So, lets start without wasting valuable time.

    Add constraint to URL

    This is very necessary for when we want to add a specific constraint to our URL. Say, for example we want a URL.

    So, we want to set some constraint string after our host name. Fine, lets see how to implement it.

    Its very simple to implement, just open the RouteConfig.cs file and you will find the routing definition in that. And modify the routing entry as in the following. We will see that we have added “abc” before.

    Controller name, now when we browse we need to specify the string in the URL, as in the following:

    Learn more here – Route Constraints in MVC

    Top MVC Interview Questions And Answers | ASP.NET MVC Interview Questions And Answers | Simplilearn

    Related Posts

    Leave a Reply

    Your email address will not be published. Required fields are marked *