title: MVC 3 Razor. Partial View validation is not working
body: <p>I'm having the problem that I cannot get client-side validation to fire from within my partial view, that loads into a div after a user clicks a button. In this example I've stopped the div from "toggling" to see if the validation fires, but to no avail, nothing happens.</p>
  
  <p>Luckily, the model doesn't accept any invalid input, but it also doesn't warn the user of the actual mistake. Any help would be appreciated.</p>
  
  <p><strong>Here is my Model:</strong></p>
  
  <pre><code>public class Help
  {
      [HiddenInput(DisplayValue=true)]
      public int HelpID { get; set; }
  
      [Required(ErrorMessage = "Please enter a proper URL")]
      public string URL { get; set; }
  
      [Required(ErrorMessage = "Please enter a content description:")]
      [DataType(DataType.MultilineText)]
      public string HelpContent { get; set; }
  
      /*? 2 properites are nullable*/
      public DateTime? createDateTime { get; set; }
      public DateTime? modifiedDateTime { get; set; }        
  }
  </code></pre>
  
  <p><strong>Here is my Controller:</strong></p>
  
  <pre><code>namespace HelpBtn.WebUI.Controllers
  {
      /*Create the admin controller*/
      public class AdminController : Controller
      {
          //declare interface object
          private IHelpRepository repository;
  
          /*Pass a db interface to controller*/
          public AdminController(IHelpRepository repo)
          {
              repository = repo;
          }
  
          /*default admin screen. displays help table obs*/
          public ViewResult Index()
          {
              return View();
          }
  
          /*Returns add view form*/
          public ViewResult AddForm()
          {
              return View();
          }
  
          /*Returns edit view form, searches for object to edit with id
            if no id provided, 0 by default*/
          public ViewResult EditForm(int helpID = 0)
          {
              Help help = repository.Help.FirstOrDefault(q =&gt; q.HelpID == helpID);
              return View(help);
          }
  
          /*Will handle the post for the edit screen after user has
            submitted edit information*/
          [HttpPost]
          [ValidateInput(false)] //this allows admin to place html in field. may cause validation problems
          public ActionResult EditForm(Help help)
          {
  
              if (ModelState.IsValid) //if all fields are validated
              {
                  //set the edit date
                  help.modifiedDateTime = DateTime.Now;
                  repository.SaveHelp(help);
                  return RedirectToAction("Index");
              }
              else //there is something wrong. send back to view            
              {
                  return View(help);
              }
          }
  
          /*Delete action method, searches with id*/
          [AcceptVerbs(HttpVerbs.Post)]
          [GridAction]
          public ActionResult Delete(int helpId)
          {
              Help helpDel = repository.Help.FirstOrDefault(p =&gt; p.HelpID == helpId);
              if (helpDel != null) //if the object is found, delete
              {
                  repository.DeleteHelp(helpDel);
              }
  
              //in all cases return to index
              return RedirectToAction("Index");
          }
  
          /*Used by the telerik table to rebind grid*/
          [GridAction]
          public ActionResult AjaxBinding()
          {
              return View(new GridModel(repository.Help));
          }
      }//end admin class
  }//end namespace
  </code></pre>
  
  <p><strong>Here is my Main View:</strong></p>
  
  <pre><code>&lt;div id="addContent" style="display: none"&gt;&lt;/div&gt;
  
  //Select Function. saves selected row
  function onRowSelect(e) {
      HelpID = e.row.cells[0].innerHTML;
  } //end onRowSelect
  
  //Refresh grid function
  function refreshGrid() {
      $("#Grid").data('tGrid').rebind();
  } //end refresh grid
  
  //Variables. '$' b4 name for intellisense
  var HelpID;
  var $editContent = $("#editContent");
  var $addContent = $("#addContent");
  //end variables  
  
  //Add Form call. loads partial view to div:content
  $("#Add").click(function () {
      $editContent.hide();
      $editContent.html("");
      $.ajax({
          type: "Get",
          url: "/Admin/AddForm",
          datatype: "html",
          success: function (data) {
              $addContent.html(data);
              $addContent.toggle();
          } //end success
      }); //end ajax
  });        //end add
  
  //Edit Form call. loads partial view to div:content
  $("#Edit").click(function () {
      $addContent.hide();
      $addContent.html("");
      $.ajax({
          type: "Get",
          url: "/Admin/EditForm",
          dataType: "html",
          data: { HelpID: HelpID },
          success: function (data) {
              $editContent.html(data);
              $editContent.toggle();
          } //end sucess
      }); //end ajax
  });         //end edit
  
  //Delete call. deletes selected row in table
  $("#Delete").live('click', function () {
      $.post("/Admin/Delete", { HelpID: HelpID }, function () {
          $addContent.html("");
          $editContent.html("");
          refreshGrid();
      }); //end function
  });   //end delete
  
  //post add form data back to server
          $("#btnAdd").live('click', function (e) {
              e.preventDefault();
              $.post($('#Addx').attr('action'), $('#Addx').serialize(), function (data) {
                  refreshGrid();
               $addContent.html("");
              }); //end post
              e.preventDefault();
          });
          //    end .live
  
          //post edit form data back to server
          $("#btnEdit").live('click', function (e) {
              $.post($('#Editx').attr('action'), $('#Editx').serialize(), function (data) {
                  refreshGrid();
                  $editContent.html("");
              });
  
              e.preventDefault();
          }); //end post edit
  </code></pre>
  
  <p><strong>And here is my partial view, that loads into the main page's div:</strong></p>
  
  <pre><code>@model HelpBtn.Domain.Entities.Help
  @*THIS POSTS BACK TO EDIT/ADMIN. needs to be asynchronous*@
  @using (Html.BeginForm("EditForm", "Admin", FormMethod.Post, new { id = "Addx" }))
  {
      &lt;fieldset&gt;
          &lt;legend&gt;Add Entry&lt;/legend&gt;
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.URL)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.URL)
              @Html.ValidationMessageFor(model =&gt; model.URL)
          &lt;/div&gt;
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.HelpContent, "Help Content")
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.HelpContent)
              &lt;p&gt;
                  @Html.ValidationMessageFor(model =&gt; model.HelpContent, "Enter a value")
              &lt;/p&gt;
          &lt;/div&gt;
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.createDateTime, "Created Date")
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.createDateTime)
              @Html.ValidationMessageFor(model =&gt; model.createDateTime)
          &lt;/div&gt;
          &lt;p&gt;
              &lt;input id="btnAdd" type="submit" value="Create" /&gt;
          &lt;/p&gt;
      &lt;/fieldset&gt;   
  }
  </code></pre>