locked
Resource is there but it says The resource cannot be found. RRS feed

  • Question

  • User1052662409 posted

    Hi All,

    In my MVC application there is a menu. See the below image. I Press F12 and find the rendered html.

    Untitled

    I have both controllers EmailSettingsController and BeneficiaryController and both have Index views.

    The strange this that when I click <a href="/EmailSettings/Index/1>Email Settings</a> it works perfectly but when I click <a href="/Beneficiary/Index/1>Payment recipient</a>

    it shows the below result.

    Untitled

    As you van see the url in address bar. I am unable to find out the cause, because there is nothing wrong with my controller and views both exists.

    Please suggest.

    Friday, May 31, 2019 11:32 AM

Answers

  • User1052662409 posted

    Sorry guys, Actually I made a mistake. 

    My controller and action comes dynamically from database. So after updating the data base I did not update the model (.edmx file).

    Now I have updated it and it's working fine.

    Thanks 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 3, 2019 10:33 AM

All replies

  • User475983607 posted

    First rebuild the application if you made recent changes.  If rebuild has no affect, then you are missing either the Beneficiary controller, the Index method, or the Index method is configured as [HttpPost] and does not have an [HttpGet]. 

    Friday, May 31, 2019 1:29 PM
  • User1052662409 posted

    you are missing either the Beneficiary controller, the Index method, or the Index method is configured as [HttpPost] and does not have an [HttpGet]. 

    Below is my controller.

    using CP.Models;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace CP.Controllers
    {
        public class BeneficiaryController : Controller
        {
            private CPMVCEntities1 db = new CPMVCEntities1();
    
            // GET: Beneficiary
            public ActionResult Index()
            {
                return View();
            }
    
            #region Select
            [HttpGet] // gettig data for jquery datatables in json format
            public JsonResult getData()
            {
                int country_id = Convert.ToInt32(Session["USER-Country"].ToString());
                var jsonData = new
                {
                    data = db.Beneficiary_Master.Where(m => m.CountryID == country_id)
                };
                return Json(jsonData, JsonRequestBehavior.AllowGet);
            } 
            #endregion
    
            #region Insert
            // GET: Beneficiary/Create
            public ActionResult Create()
            {
                return View();
            }
    
            // POST: Beneficiary/Create
            [HttpPost]
            public ActionResult Create(FormCollection collection)
            {
                try
                {
                    // TODO: Add insert logic here
    
                    return RedirectToAction("Index");
                }
                catch
                {
                    return View();
                }
            } 
            #endregion
    
            #region Edit / Update
            // GET: Beneficiary/Edit/5
            public ActionResult Edit(int id)
            {
                return View();
            }
    
            // POST: Beneficiary/Edit/5
            [HttpPost]
            public ActionResult Edit(int id, FormCollection collection)
            {
                try
                {
                    // TODO: Add update logic here
    
                    return RedirectToAction("Index");
                }
                catch
                {
                    return View();
                }
            } 
            #endregion
    
            #region Delete
            // GET: Beneficiary/Delete/5
            public ActionResult Delete(int id)
            {
                return View();
            }
    
            // POST: Beneficiary/Delete/5
            [HttpPost]
            public ActionResult Delete(int id, FormCollection collection)
            {
                try
                {
                    // TODO: Add delete logic here
    
                    return RedirectToAction("Index");
                }
                catch
                {
                    return View();
                }
            } 
            #endregion
        }
    }

    And I am wondering the same methods for another control are working fine, but not for the current controller.

    Please suggest.

    Monday, June 3, 2019 3:35 AM
  • User-2054057000 posted

    The strange this that when I click <a href="/EmailSettings/Index/1>Email Settings</a> it works perfectly but when I click <a href="/Beneficiary/Index/1>Payment recipient</a>

    it shows the below result.

    Untitled

    When you open a url in the browser then HTTP GET request is made. Now when you click submit button on a form that has a type of HTTP POST than the HTTP POST type request is made. I recommend you to check whether you have both HTTP GET AND HTTP POST types of ACTION Methods given in your controller.

    Monday, June 3, 2019 3:54 AM
  • User1052662409 posted

    I recommend you to check whether you have both HTTP GET AND HTTP POST types of ACTION Methods given in your controller.

    Yes I have both, you can see my previous reply on same post. 

    Monday, June 3, 2019 4:10 AM
  • User1520731567 posted

    Hi demoninside9,

    This is very strange.

    In my opinion, there is nothing wrong with your code.

    Just missing parameters, but that doesn't cause this error.

    Are EmailSettingsController and BeneficiaryController in different areas?

    If so,you need to modify redirect with Area,for example:

    @Html.ActionLink("Payment recipient", "Index", "Beneficiary", new { area = "AreaName" }, null)
    

    Best Regards.

    Yuki Tao

    Monday, June 3, 2019 6:29 AM
  • User1052662409 posted

    Yuki Tao

    new { area = "AreaName" }

    I am not using any area

    Untitled

    Monday, June 3, 2019 9:29 AM
  • User1052662409 posted

    Sorry guys, Actually I made a mistake. 

    My controller and action comes dynamically from database. So after updating the data base I did not update the model (.edmx file).

    Now I have updated it and it's working fine.

    Thanks 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 3, 2019 10:33 AM