-1

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

enter image description here

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

4
  • 3
    Please don't post images of text. Copy-paste text as text into the question. Commented Sep 8, 2022 at 8:45
  • 1
    So, when you click on Create button the public ActionResult Create(TourismCategory Info) action does not hit? Commented Sep 8, 2022 at 8:46
  • 1
    your paramter is TourismCategory Info. But your view does not contain Info Commented Sep 8, 2022 at 10:18
  • Side Note - "I am new to asp.net MVC 4" Why are you using ASP.NET MVC 4! If you have to use .NET Framework then you should be using ASP.NET MVC 5. Commented Sep 8, 2022 at 14:53

1 Answer 1

1

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 } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.