我在WebGrid中输出一个动态链接文本的Actionlink,我可以让它工作的唯一方法如下:
Grid.Column(header: "Subject", columnName: "Message.Subject", format:(item) => Html.ActionLink(((object)item.Message.Subject).ToString(), "Message", new {Id = 12345 }))
Run Code Online (Sandbox Code Playgroud)
有没有人有更好的方法这样做?
我们有一个MVC 5.1项目,正在使用属性路由.一切都工作正常,除了默认页面上有登录表单.
[RoutePrefix("Home")]
public class HomeController : BaseController
{
[Route("~/")]
[Route]
[Route("Index")]
[HttpGet]
public ActionResult Index()
{
var model = new LoginViewModel();
return View(model);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Index(String Username, String Password)
Run Code Online (Sandbox Code Playgroud)
表格通过GET罚款显示,但在POST后我们得到......
HTTP错误405.0 - 不允许的方法
由于使用了无效的方法(HTTP动词),因此无法显示您要查找的页面.
通常,默认路由将处理POST和GET罚款.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}/{dealerId}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
显然我在默认路由上的帖子的路由中遗漏了一些东西,因为其他页面上的后续帖子工作正常.
有没有人这样做过?
谢谢,
c# asp.net-mvc-routing attributerouting asp.net-mvc-5 asp.net-mvc-5.1
c# ×1