Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

script in mvc razor editortemplate

I am using an editortemplate, I have shown partial code below. The script tag repeats for each of the rows being rendered by the partial view.

Is there a way to get the script tag into the page header, or at the very least have it included in the page only once?

I would like the code in the partial view as that is where it truly belongs.


@* DisplayTemplates/contact.cshtml *@
@model Online.Web.Contacts.Contact

<script id="xxx">
  stuff here.
</script>

<tr>
   <td>@Html.EditorFor(x => x.FirstName)</td>
</tr>
like image 776
Jim Avatar asked Nov 06 '22 03:11

Jim


1 Answers

You could try this:

@model IEnumerable<Online.Web.Contacts.Contact>
<script id="xxx">
  stuff here.
</script>
@Html.EditorForModel()

and then another editor template for a single contact:

@model Online.Web.Contacts.Contact
<tr>
   <td>@Html.EditorFor(x => x.FirstName)</td>
</tr>
like image 126
Darin Dimitrov Avatar answered Nov 09 '22 17:11

Darin Dimitrov