Asp Net Mvc Experienced Interview Questions

1 What are the Main Razor Syntax Rules?

Answer

  • 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

    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

    2) What does Model-View-Controller represent in an MVC application?

  • Model– It represents the application data domain. In other words, an application’s business logic is contained within the model and is responsible for maintaining data.
  • View– It represents the user interface with which end-users communicate. In short, all the user interface logic is contained within View.
  • Controller- It is the controller that answers the user’s actions. Based on the user actions, the respective controller responds within the model and chooses a view to render that displays the user interface. The user input logic is contained within the controller.
  • 4 What is the use of remote validation in MVC?

    Answer

    Remote validation is the process where we validate specific data posting data to a server without posting the entire form data to the server. Lets see an actual scenario, in one of my projects I had a requirement to validate an email address, whetehr it already exists in the database. Remote validation was useful for that; without posting all the data we can validate only the email address supplied by the user.

    Practical Explanation

    Lets create a MVC project and name it accordingly, for me its “TestingRemoteValidation”. Once the project is created lets create a model named UserModel that will look like:

    Lets get some understanding of the remote attribute used, so the very first parameter “CheckExistingEmail” is the the name of the action. The second parameter “Home” is referred to as controller so to validate the input for the UserEmailAddress the “CheckExistingEmail” action of the “Home” controller is called and the third parameter is the error message. Lets implement the “CheckExistingEmail” action result in our home controller.

    Learn more here – Remote Validation 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 *