How to add validators for @Html.TextBox() without model

Bhavin Bhaskaran

This is a part of my view

@model bhavin.Models.Employee

@using (Html.BeginForm("BuynowForm", "Home"))
{
<div class="form-group">
   <label>Billing Address</label>
   @Html.TextBox("bill_address", null, new { @class = "form-control valid" })
</div>
<p>
<input type="submit" value="Submit" class="btn btn-primary" />
</p>
 }

I want to add required validation to it. The billing_address textbox is not a part of the models.employee. I am using mvc5 So how to add the validator?

ramiramilu

Add data-val and data-val-required attribute for Html.TextBox() as shown below.

<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>    

@using (Html.BeginForm("",""))
{
    @Html.ValidationSummary()
    @Html.TextBox("bill_address", null, new { @class = "form-control valid", @data_val = "true", @data_val_required = "Billing Address is required" })
    <input type="submit" value="Click" id="btnSubmit" />
}

NOTE

  1. @Html.ValidationSummary() is used for printing validation message.
  2. Do not forget to include - validate and unobtrusive JavaScript files.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Html textbox without model in Yii2

From Dev

NUMBERS ONLY: TextBox in GridView without validators

From Dev

How to add Validators in Vaadin 8?

From Dev

Validating a textbox without a model

From Dev

Validating a textbox without a model

From Dev

Validate HTML Textbox in MVC 5 without Model and Entity Framework

From Dev

How to validate a variable in PHP using standard Yii2 validators without creating a model?

From Dev

How to add a rich Textbox (HTML) to a table cell?

From Dev

How to mutate validators of fields in model serializer

From Dev

how to add the model to collection without duplicating?

From Dev

(Laravel) How to add errors in custom validators?

From Dev

How to add validators to a formModel in angular reactive forms

From Dev

How to add composeAsync to angular 5 validators

From Dev

HTML Add value in textbox

From Dev

how to add a DOM model in a HTML structure?

From Dev

How to add a prefix "91" to a textbox using Jquery or HTML

From Dev

How to remove a textbox from html table using jquery or javascript without losing the textbox values

From Dev

How to add additional fields to embedded documents without changing the original model

From Dev

How to clear textbox in html

From Dev

How to add multiple pattern-based validators with parsley.js?

From Dev

How do I add custom validators in JOI 17?

From Dev

add independent validators to controls

From Dev

How to add ng-app to html element without access to html

From Dev

How to add HTML in GXT HTML Layout Container without root element?

From Dev

How to add textBox programmatically into Grid?

From Dev

How to add a value to a textbox with Javascript

From Dev

How To Add Validation in Textbox in Jquery

From Dev

How to add textBox programmatically into Grid?

From Dev

how to add some textbox with Code

Related Related

  1. 1

    Html textbox without model in Yii2

  2. 2

    NUMBERS ONLY: TextBox in GridView without validators

  3. 3

    How to add Validators in Vaadin 8?

  4. 4

    Validating a textbox without a model

  5. 5

    Validating a textbox without a model

  6. 6

    Validate HTML Textbox in MVC 5 without Model and Entity Framework

  7. 7

    How to validate a variable in PHP using standard Yii2 validators without creating a model?

  8. 8

    How to add a rich Textbox (HTML) to a table cell?

  9. 9

    How to mutate validators of fields in model serializer

  10. 10

    how to add the model to collection without duplicating?

  11. 11

    (Laravel) How to add errors in custom validators?

  12. 12

    How to add validators to a formModel in angular reactive forms

  13. 13

    How to add composeAsync to angular 5 validators

  14. 14

    HTML Add value in textbox

  15. 15

    how to add a DOM model in a HTML structure?

  16. 16

    How to add a prefix "91" to a textbox using Jquery or HTML

  17. 17

    How to remove a textbox from html table using jquery or javascript without losing the textbox values

  18. 18

    How to add additional fields to embedded documents without changing the original model

  19. 19

    How to clear textbox in html

  20. 20

    How to add multiple pattern-based validators with parsley.js?

  21. 21

    How do I add custom validators in JOI 17?

  22. 22

    add independent validators to controls

  23. 23

    How to add ng-app to html element without access to html

  24. 24

    How to add HTML in GXT HTML Layout Container without root element?

  25. 25

    How to add textBox programmatically into Grid?

  26. 26

    How to add a value to a textbox with Javascript

  27. 27

    How To Add Validation in Textbox in Jquery

  28. 28

    How to add textBox programmatically into Grid?

  29. 29

    how to add some textbox with Code

HotTag

Archive