Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating simple web application using MVC(Code first) Which consist of two page one with which admin can add category and its description and other with Which Select Category and can insert Status in that particular category.When i run status page i am getting Error 404:The resource cannot be found.

Category insertion is working properly but i am getting error on status page.

What I have tried:

Here is an my Route Config file:

C#
public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            //routes.MapRoute(
            //    name: "Default",
            //    url: "{controller}/{action}/{id}",
            //    defaults: new { controller = "Category", action = "CreateCategory", id = UrlParameter.Optional }
            //);

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Status", action = "StatusList", id = UrlParameter.Optional }
            );

           
        }
I have tried project name>Properties>Web>Specific page but yet i am getting the same error.
Posted
Updated 30-Jan-17 1:40am
v2
Comments
Nathan Minier 30-Jan-17 8:23am    
The routeconfig is only partially useful. What about the code for your StatusController?
Kalpesh Khandla 30-Jan-17 8:40am    
using System;
using System.Collections.Generic;
Code for My StatusController :

using System.Linq;
using System.Web;
using System.Web.Mvc;
using StatusCraft.Models;
using StatusCraft.Service;

namespace StatusCraft.Controllers
{
public class StatusController : Controller
{

StatusServices StaServices = new StatusServices();

//
// GET: /Status/

public ActionResult CreateStatus(int? StatusId)
{
if (StatusId == null)
{
return View();
}
else
{
return View(StaServices.GetStatusByStatusID(Convert.ToInt32(StatusId)));
}

}

[HttpPost]
public ActionResult CreateStatus(StatusMasterModel status, int? StatusId)
{
if (StatusId == null)
{
try
{
status.CreatedBy = 1;
StaServices.AddStatus(status);
ViewBag.msg = "Insert Successfull";
ModelState.Clear();
}
catch (Exception ex)
{
ViewBag.msg = ex.ToString();

}
return View();

}
else
{
var updateStatus = StaServices.GetStatusByStatusID(Convert.ToInt32(StatusId));
updateStatus.StatusName = status.StatusName;
updateStatus.CategoryId = status.CategoryId;
updateStatus.UpdatedBy = 1;
updateStatus.IsActive = status.IsActive;
updateStatus.IsDeleted = status.IsDeleted;
StaServices.UpdateStatus(updateStatus);
return RedirectToAction("StatusList");
}

}

public ActionResult StatusList()
{
return View(StaServices.GetStatusList());
}

}
}
Nathan Minier 30-Jan-17 9:09am    
That looks right.

You have a /Views/Status/StatusList.cshtml file in the project? Is it setup to take your Model type?
Kalpesh Khandla 30-Jan-17 9:27am    
Yes, there is a statusList.cshtml And is as below :

@model IEnumerable<statuscraft.models.statusmastermodel>

@{
ViewBag.Title = "StatusList";
Layout = "~/Views/Shared/_AdminLayout.cshtml";
}

StatusList



@Html.ActionLink("Create New", "Create")

@foreach (var item in Model) {
}


@Html.DisplayNameFor(model => model.Category.CategoryName)

@Html.DisplayNameFor(model => model.StatusName)

@Html.DisplayNameFor(model => model.CreatedBy)

@Html.DisplayNameFor(model => model.CreatedDate)

@Html.DisplayNameFor(model => model.UpdatedBy)

@Html.DisplayNameFor(model => model.UpdatedDate)

@Html.DisplayNameFor(model => model.IsDeleted)

@Html.DisplayNameFor(model => model.IsActive)

@Html.DisplayFor(modelItem => item.Category.CategoryName)

@Html.DisplayFor(modelItem => item.StatusName)

@Html.DisplayFor(modelItem => item.CreatedBy)

@Html.DisplayFor(modelItem => item.CreatedDate)

@Html.DisplayFor(modelItem => item.UpdatedBy)

@Html.DisplayFor(modelItem => item.UpdatedDate)

@Html.DisplayFor(modelItem => item.IsDeleted)

@Html.DisplayFor(modelItem => item.IsActive)

@Html.ActionLink("Edit", "Edit", new { id=item.StatusId }) |
@Html.ActionLink("Details", "Details", new { id=item.StatusId }) |
@Html.ActionLink("Delete", "Delete", new { id=item.StatusId })
Nathan Minier 30-Jan-17 12:47pm    
Your pipeline looks right. I'm afraid all I can suggest at this point is making sure that IIS Express is doing the right things. Sorry I can't be of more help to you.

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