Right now I just output my value(s) like
<input type="text" class="form-control" value="@Name" id="name" placeholder="Name">
But I've seen a lot about @HTML display something?
Should I use HTML display, and if so, how and why?
Right now I just output my value(s) like
<input type="text" class="form-control" value="@Name" id="name" placeholder="Name">
But I've seen a lot about @HTML display something?
Should I use HTML display, and if so, how and why?
The Html helper class is there to encapsulate writing a lot of html code in a single call:
- the actual field
- validation rules according to your model Field Attributes
- the validation place holder
- Value binding
additionally, allows you to change the behavior and html of all your fields in case needed, in one spot.
it is, like many other things, a tool...
use it if you wish...
for my opinion, it rule and should be used.
You can do it either way. @Html.TextBox and @Html.TextBoxFor will automatically generate the html for you, but you can do it yourself if you want.
Personally, I prefer writing my own html, but that's just me...
The @ symbol allows you to access c# code within your cshtml file so you can mix html and c# code to generate a final html output. For more information, search for C# Razor syntax, here's a link for more info http://www.w3schools.com/aspnet/razor_syntax.asp and http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx/
The benefit of using Razor syntax is the ability to access helper c# methods, global variables, view model variable object passed from the controller, view compile time errors (by default, it's off in visual studio, check http://haacked.com/archive/2011/05/09/compiling-mvc-views-in-a-build-environment.aspx/ for more info), you don't need to use javascript to populate a form or other fields dynamically ...etc
The downsides are your code needs to be compile to html so browsers can process it, a syntax error can crash your whole page, your cshtml code is not portable in case you decide to switch backend engine, ...etc