Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Team

What could have cause an issue with the reason cannot be found in asp.net mvc?

I have created create operation and uses Get. could be the reason i am using httpPost? Please advice me, thanks

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using OrderApplicationXML.Data_Access_Layer;
using OrderApplicationXML.Models;

namespace OrderApplicationXML.Controllers
{
    public class OrderController : Controller
    {
        // GET: Order
        public ActionResult Index()
        {
            var orders = OrderXmlDataAccess.GetAllOrders();
            return View(orders);
        }


        // GET:/Create.
        public ActionResult Create()
        {
            
            return View();
        }

        //POST:Create.
        [HttpPost]
        public ActionResult Create(SalesOrder order)
        {   
            if(ModelState.IsValid)
            {
                OrderXmlDataAccess.AddOrder(order);
                return RedirectToAction("Index");
            }
            return View(order);
        }

        // GET:/Details.
        public ActionResult Details(string id)
        {
            var order = OrderXmlDataAccess.GetOrderById(id);
            if(order == null)
            {
                return HttpNotFound();
            }
            return View(order);
        }

        // POST: Edit.
        [HttpPost]
        public ActionResult Edit(SalesOrder order)
        {
            if(ModelState.IsValid)
            {
                OrderXmlDataAccess.UpdateOrder(order);
                return RedirectToAction("Index");
            }

            return View(order);
        }

        // delete an order.
        public ActionResult Delete(string id)
        {
            var order = OrderXmlDataAccess.GetOrderById(id);
            if(order == null)
            {
                return HttpNotFound();
            }
            
            return View(order);
        }
        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(string id)
        {
            OrderXmlDataAccess.DeleteOrder(id);
            return View();
        }
    }
}
ASP.NET

Posted
Updated 5-Jun-23 22:45pm
v2
Comments
Shahin Khorshidnia 5-Jun-23 19:13pm    
Is there any error message you are getting?
Gcobani Mkontwana 6-Jun-23 2:10am    
@Shahin its an error itself, is it because must i use correct routing config for this URL? I tried to use it but was not successful. Hence i am using post itself from the form.
Shahin Khorshidnia 6-Jun-23 4:11am    
Your code looks correct. But, without seeing the routing configuration and the rest of your code, I cann't say for sure if everything is correct.

Have you checked the URL in the form action attribute and made sure if it matched the routing config?
Andre Oosthuizen 6-Jun-23 4:40am    
Please show the code of your Controller class as it seems that the calls made in your code above does not match the functions in your class.
Gcobani Mkontwana 6-Jun-23 4:45am    
@Andre Oosthuizen i have made the changes, please have a look at the controller class.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900