title: How to add custom error message with “required” htmlattribute to mvc 5 razor view text input editor
body: <p>I am naive to Asp.Net MVC.</p>
  
  <p>I have a partial view(ASP.Net MVC) in which I have some required fields I want to show custom error message if any of the required field in not provided. Below is the complete cshtml code for my partial view.</p>
  
  <pre><code>@model CMSAdminPanel.ViewModel.ProductView
  &lt;h4&gt;Material And Labour Cost For Each Size&lt;/h4&gt;
  &lt;hr /&gt;
  @Html.ValidationSummary(false, "", new { @class = "text-danger" })
  @for (int i = 0; i &lt; Model.ServiceView.ListPriceView.Count; i++)
  {
      @Html.HiddenFor(x =&gt; x.ServiceView.ListPriceView[i].ProductSizeType)
      &lt;div class="form-group"&gt;
          @Html.LabelFor(x =&gt; x.ServiceView.ListPriceView[i].ProductSizeTypeName, "Size - " + Model.ServiceView.ListPriceView[i].ProductSizeTypeName, htmlAttributes: new { @class = "control-label col-md-4" })
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(x =&gt; x.ServiceView.ListPriceView[i].LabourCost, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(x =&gt; x.ServiceView.ListPriceView[i].LabourCost, new { htmlAttributes = new { @class = "form-control", required = "required"} })
              @Html.ValidationMessageFor(x =&gt; x.ServiceView.ListPriceView[i].LabourCost,"", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(x =&gt; x.ServiceView.ListPriceView[i].MaterialCost, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(x =&gt; x.ServiceView.ListPriceView[i].MaterialCost, new { htmlAttributes = new { @class = "form-control", required = "required" } })
              @Html.ValidationMessageFor(x =&gt; x.ServiceView.ListPriceView[i].MaterialCost, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(x =&gt; x.ServiceView.ListPriceView[i].Profit, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(x =&gt; x.ServiceView.ListPriceView[i].Profit, new { htmlAttributes = new { @class = "form-control", required = "required" } })
              @Html.ValidationMessageFor(x =&gt; x.ServiceView.ListPriceView[i].Profit, "", new { @class = "text-danger"})
          &lt;/div&gt;
      &lt;/div&gt;
  }
  </code></pre>
  
  <p>I want to show custom message "Material cost is required" while I am getting "This field is required". So I want to override this difault error message on client side.</p>
  
  <p>I want to achieve something like this:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
          @Html.LabelFor(x =&gt; x.ServiceView.ListPriceView[i].LabourCost, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(x =&gt; x.ServiceView.ListPriceView[i].LabourCost, new { htmlAttributes = new { @class = "form-control", required = "required", **data_val_required = "LabourCost is requried"**} })
              @Html.ValidationMessageFor(x =&gt; x.ServiceView.ListPriceView[i].LabourCost,"", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>Any suggestion/solution would be great help</p>