1below I have posted my total coding of view. Here validation is not firing on the textbox. I dont know how to sort out this problem. This view is executing. if I press the search textbox without entering the text in textbox, its not validating.Also tell me wheather I have to use TextBox or TextBoxFor. I am fresher and new to mvc3. Please tell me the solution.
@model IEnumerable< ShoppingCart.Models.ShoppingClass>
@{
ViewBag.Title = "Display";
}
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
@Html.ValidationSummary(true)
@using (Html.BeginForm("Display","Home", FormMethod.Post, new { id = "loginForm" }))
{
//for (int i = 0; i < 1; i++)
//{
<table><tr>o<td> @Html.Label("BrandName")</td>
<td>@Html.TextBox("BrandName") <div> @Html.ValidationMessage("BrandName")</div></td>
<td></td></tr></table>
@* <table><tr><td>
@Html.LabelFor(o=>o[i].BrandName)</td>
<td>@Html.EditorFor(o => o[i].BrandName) <div>@Html.ValidationMessageFor(o => o[i].BrandName)</div></td>
<td></td></tr></table>*@
// }
<input type="submit" value="Search" name="Search" />
}
@{
var grid = new WebGrid(source: Model, defaultSort: "Drug_Code", rowsPerPage: 20);
<div id="grid">
@grid.GetHtml(tableStyle: "listing-border", headerStyle: "gridhead", footerStyle: "paging", rowStyle: "td-dark", alternatingRowStyle: "td-light",
columns: grid.Columns(
grid.Column("GenericName", format: @<text>@item.GenericName</text>),
grid.Column("BrandName", format: @<text>@item.BrandName</text>),
grid.Column("Purchaseqty", format: @<text>@item.Purchaseqty</text>),
grid.Column("Purchaseprice", format: @<text>@item.Purchaseprice</text>),
grid.Column("Drug_Code", format: @<text>@item.Drug_Code</text>),
grid.Column(header: "", format: (item) => Ajax.ActionLink("Add to Cart", "ADDTOCART",
new { brandname = @item.BrandName, purchaseqty = @item.Purchaseqty, drugcode = @item.Drug_Code }, new AjaxOptions { HttpMethod = "Post", OnSuccess = "ADDTOCART" }))
)
</div>
}