-1

Can I insert html designing/code with this Razor CSHTML code in same page?

@model project_final.Models.Bike
@{
  ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm()) {
  @Html.ValidationSummary(true)
  <fieldset>
    @<legend>Bike</legend>
    @<div class="editor-label">
      @Html.LabelFor(model => model.Id)
    </div>
    <div class="editor-field">
      @Html.EditorFor(model => model.Id)
      @Html.ValidationMessageFor(model => model.Id)
    </div>
    <div class="editor-label">
      @Html.LabelFor(model => model.Color)
    </div>
    <div class="editor-field">
      @Html.EditorFor(model => model.Color)
      @Html.ValidationMessageFor(model => model.Color)
    </div>
    <p>
      <input type="submit" value="Create" />
    </p>
  </fieldset>
}

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

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
Kousar Malik
  • 11
  • 1
  • 2
  • 1
    What do you mean _"html designing/code"_? What code are you referring to. And why do you have the `@` symbol in `@Bike` and `@
    `?
    –  Jun 11 '15 at 02:06
  • Did you try it? Was the answer yes or no? This can be worked out very simply just by trying it and observing what happens. – JK. Jun 11 '15 at 04:09
  • Razor is just a markup syntax for your html. You can definitely embedd HTML. – Ganesh Todkar Jun 11 '15 at 04:47

1 Answers1

2

Yes, you can.

Just beware of what is the code that need to have @ in Razor engine, and what is html tag don't need the @ like what @Stephen Muecke mentioned. @Bike does not need the @ in front of it because is html tag. Or I make a simple statement that

@ never stick with <, if you found @< in your ASP.Net View, it must be a mistake

Read the Introduction to ASP.NET Web Programming Using the Razor Syntax (C#), may be you can know more things about Razor.

By the way , you might need to read the post How can I add a class attribute to an HTML element generated by MVC's HTML Helpers? to modified the class of the HTML helper such as @Html.LabelFor

@Html.LabelFor(model => model.Id, new { @class = "col-md-2 control-label" }) 
Community
  • 1
  • 1
V-SHY
  • 3,925
  • 4
  • 31
  • 47