繁体   English   中英

ASP.NET MVC HTML.ActionLink不起作用

[英]Asp.net mvc Html.ActionLink doesnt work

routes.MapRoute(
            name: "Rss",
            url: "{controller}/{action}/{SourceSite}/{Name}",
            defaults: new { controller = "RssController", action = "Index", SourceSite = UrlParameter.Optional, Name = UrlParameter.Optional }
        );

public class RssController : Controller
{
    // GET: Rss
    public ActionResult Index(string SourceSite, string Name)
    {
        string Url = NewsResourses.common.Single(p => p.SourceSite == SourceSite & p.Name == Name).Url;
        var rssItems = GetItemsFromChannel(Url);
        ViewBag.SourceName = Name;
        return View(rssItems);
    }

但是当我尝试获取类似localhost:port / RssController / Index / Ria / Politics之类的东西时,我收到404 http异常。

你能帮我吗?

您不需要指定控件名称的Controller部分。 请尝试以下方法:

defaults: new { controller = "Rss", action = "Index", SourceSite = UrlParameter.Optional, Name = UrlParameter.Optional }

这是您需要做的:

localhost:port/Rss/Index/Ria/Politics

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM