バカです
バカです

Reputation: 185

what are those @ methods in MVC html?

All those... comands(?) or methods(?) or something... that start with the @ in the html code of a page built using the MVC. What exactly are those? Do they have a specific name so I can search a documentation page of them or something like that?

For example:

 @model MyImdb.ViewModels.MovieCreateViewModel

 <!--- ... some lines ... --->
 @{
      ViewBag.Title = "Create"; 

 }

 <!--- ... some lines ... --->

 @using (Html.BeginForm()) { @Html.AntiForgeryToken()

 <!--- ... some lines ... --->

 @Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" })

<!--- ... some lines ... --->

@Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } })

<!--- ... some lines ... --->

<div> 
    @Html.ActionLink("Back to List", "Index")
</div>

Upvotes: 1

Views: 142

Answers (1)

Ehsan Sajjad
Ehsan Sajjad

Reputation: 62498

@ in View basically means that razor code starts from here which is written in c# in asp.net mvc.

There are multiple purposes of it depending on where it is used in view, for example at the first line of the view it is just specifying the binding of the view to a Model/ViewModel to tell that which kind of data it expects.

While if we move down there, it is uses to write C# statements and calling Helper method which generate the html string the render it in the browser.

As an example when you are writing @Html.ActionLink("Back to List", "Index") it will the ActionLink method which will return Html String that will be rendered as html by the razor view engine so in this case it will be anchor tag like <a href="/Index">Back To List</a>.

This blogpost might be helpful to you and also have a look at this blogpost.

Following is the link to official documentation of razor (Thanks to @Stephen Muecke for referring to this in comments):

https://learn.microsoft.com/en-us/aspnet/core/mvc/views/razor

Hope it give some idea to you.

Upvotes: 1

Related Questions