I am new to asp.net MVC 4. i have some problems dealing with attributs
i use [httppost] attribut in my controller but action not Firing
my view
my control
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(TourismCategory Info)
{
if (ModelState.IsValid)
{
return RedirectToAction("Index");
}
else
{
return View();
}
}
think you for your help
CodePudding user response:
The post action should be like this base your question
[HttpPost]
public ActionResult Create([Bind(Include = "category,imagepth")]TourismCategory Info)
{
if (ModelState.IsValid)
{
db.TourisamCategory.Add(Info); // declare your dbcontext in the appropirate place
db.SaveChanges();
return RedirectToAction("Index");
}
else
{
return View(Info); // return the model if save failed
}
}