Home > Back-end >  asp.net mvc [HttpPost] not firing
asp.net mvc [HttpPost] not firing

Time:09-09

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

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
                }
    
    
            }
  • Related