下面的代码是我在向控制器提交传递空值后键入的示例,在控制器中,我使用了类名,然后正确传递了值,但是当我使用参数时,它将 NULL 值传递给控制器。请给我一个解决方案..
控制器:
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string firstname)
{
LogonViewModel lv = new LogonViewModel();
var ob = s.Newcustomer(firstname)
return View(ob );
}
看法:
@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" />
}
}
模型:
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>();
..
}