The below code is sample I typed
After I submit passing null values to controller, In Controller I have used the Class name then value passing correctly but when i used the parameter it passing NULL values to the controller. Please give me a solution..
Controller:
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string firstname)
{
LogonViewModel lv = new LogonViewModel();
var ob = s.Newcustomer(firstname)
return View(ob );
}
View:
@model IList<clientval.Models.LogonViewModel>
@{
ViewBag.Title = "Index";
}
@using (Html.BeginForm())
{
for (int i = 0; i < 1; i++)
{
@Html.LabelFor(m => m[i].UserName)
@Html.TextBoxFor(m => m[i].UserName)
@Html.ValidationMessageFor(per => per[i].UserName)
<input type="submit" value="submit" />
}
}
Model:
public class LogonViewModel
{
[Required(ErrorMessage = "User Name is Required")]
public string UserName { get; set; }
}
public List<ShoppingClass> Newcustomer(string firstname1)
{
List<ShoppingClass> list = new List<ShoppingClass>();
..
}
Its working.. I have changed my controller as written below
Controller: