title: Is there a "standard MVC" way of mixing Javascript and Razor?
body: <p>I really dislike page loads, I think they detract from the user experience, so I'm trying to make my web application heavily AJAX-ified.</p>
  
  <p>When the user clicks on "Add new", Javascript generates a form based on a model using Razor, with the following code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
      var strNewCategoryForm = '&lt;div&gt;&lt;i class="glyphicon glyphicon-folder-open rightfolderpadding"&gt;&lt;/i&gt;@using (Html.BeginForm("AddCategory", "Password", FormMethod.Post, new { @class="newcategoryform", role = "form", id="[1]" })) { @Html.AntiForgeryToken() @Html.PasswordFor(m =&gt; m.Category_ParentID, new { type = "hidden", value = "0" }) @Html.PasswordFor(m =&gt; m.CategoryName, new { type = "text" })  &lt;span class="btn-group groupalign"&gt;&lt;a href="#" onclick="saveNewCategory(\'#[2]\');return false;" class="btn btn-xs btn-primary"&gt;&lt;i class="glyphicon glyphicon-save"&gt;&lt;/i&gt;Save&lt;/a&gt;&lt;/span&gt; }&lt;/div&gt;';
  
  &lt;/script&gt;
  </code></pre>
  
  <p>The code works great, Razor is able to generate the form within the string, so I dont have any issues with making this work.
  However, for code readability and ease of development, it's not that great.</p>
  
  <p>I'm still quite new to MVC and razor, so I'm just wondering, is there a better or "MVC/Razor standard" way of doing this, that I don't know about?</p>
  
  <p>Edit:
  In case anyone is interested, I've used both bits of Exception's answers:</p>
  
  <p>In the partial view:</p>
  
  <pre><code>@model Secure_Password_Repository.Models.Category
  
  &lt;div&gt;&lt;i class="glyphicon glyphicon-folder-open rightfolderpadding"&gt;&lt;/i&gt; \
      @using (Ajax.BeginForm("AddCategory", "Password", new AjaxOptions { HttpMethod="post", OnFailure="" }, new { @class="newcategoryform", role = "form", id="[1]" })) 
      { 
      @: \
      @Html.AntiForgeryToken() @: \
      @Html.HiddenFor(m =&gt; m.Category_ParentID, new { value = "0" }) @: \
      @Html.TextBoxFor(m =&gt; m.CategoryName) @: \
      @: &lt;span class="btn-group groupalign"&gt;&lt;a href="#" onclick="saveNewCategory(\'#[2]\');return false;" class="btn btn-xs btn-primary"&gt;&lt;i class="glyphicon glyphicon-save"&gt;&lt;/i&gt;Save&lt;/a&gt;&lt;/span&gt;  \
      }&lt;/div&gt;
  </code></pre>
  
  <p>In the main view:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
      var strNewCategoryForm = '@Html.Partial("_NewCategoryForm")';
  
  &lt;/script&gt;
  </code></pre>
  
  <p>The "\" at the end of each line in the partial view tell JavaScript that each line is continuation of a string value.</p>