enter code here
我使用客户端表单验证,但它不起作用。
我的模型:
[Key]
public int Id { get; set; }
[Required(ErrorMessage = "Error")]
[RegularExpression(@"^[0-9\.]*$",ErrorMessage="Error")]
public string Scode { get; set; }
我的观点:
@Html.ValidationSummary(true)
@using(Html.BeginForm("CreateSharshomari", "VahedInfo", FormMethod.Post))
{
@Html.TextBox("Scode")
@Html.ValidationMessage("Scode")
<input id="BtnErsal" type="submit" value="ارسال" />
}
有什么问题?
它是我的控制器。我想也许我对此有问题。请看它并说出你的意见。
public PartialViewResult CreateSharshomari()
{
IEnumerable<Lcity> Lcitys = Dbcon.Lcitys;
IEnumerable<RFaaliat> RFaaliats = Dbcon.RFaaliats;
var query = Lcitys.Select(x => new SelectListItem
{
Value = x.Citycode.ToString(),
Text = x.CityName,
Selected = x.Citycode == 1
});
var query1 = RFaaliats.Select(x => new SelectListItem
{
Value = x.IDReshteh.ToString(),
Text = x.ReshteName,
Selected = x.IDReshteh == 1
});
var model = new CityFaaliatViewModel
{
Lcitylist = query.AsEnumerable(),
RFaaliatList = query1.AsEnumerable()
};
return PartialView(model);
}
[HttpPost]
public ActionResult CreateSharshomari(TaavoniInfo Info,CityFaaliatViewModel selcode)
{
try
{
TaavoniInfo idcity = Info;
idcity.idCitycode = Convert.ToInt32(selcode.SelectedCitycode);
idcity.idIDReshteh = Convert.ToInt32(selcode.SelectedIDReshteh);
Dbcon.TaavoniInfos.Add(idcity);
Dbcon.SaveChanges();
ViewBag.SuccessMsg = "success";
return View();
}
catch
{
ViewBag.SuccessMsg = "error";
return View();
}
}
请帮我。