我正在尝试确定如何将/ News/5的路由映射到我的新闻控制器.
这是我的NewsController:
public class NewsController : BaseController
{
//
// GET: /News
public ActionResult Index(int id)
{
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的Global.asax.cs规则:
routes.MapRoute(
"News", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "News", action = "Index", id = -1 } // Parameter defaults
);
Run Code Online (Sandbox Code Playgroud)
我尝试去/ News/5但是我收到了资源未找到错误,但是当进入/ News/Index/5时它有效吗?
我尝试过,{controller}/{id}但这只是产生了同样的问题.
谢谢!
在将我的MVC 3 Web应用程序发布到我的网站后,我收到一条错误,指出未将对象引用设置为对象的实例.
'错误'行是:第2行: ViewBag.Title = "Index";
这是我的索引视图:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
Run Code Online (Sandbox Code Playgroud)
这是我的家庭控制器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我上传了DLL的:
System.Web.Helpers
System.Web.Mvc
System.Web.Razor
System.Web.WebPages
System.Web.WebPages.Deployment
System.Web.WebPages.Razor
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助