2011-10-15 35 views
1

我有問題與asp mvc 3應用程序。當我把+字符放在一個網址中時,我總是得到一個404錯誤。所有請求都是ajax獲取請求。asp mvc 404當+在url

如果我提出這個要求測試/詳細信息/ +我得到404:測試/詳細信息/ +

這是請求小提琴手:GET /Test%2FDetails%2F%2B?t=1318678807718 HTTP/1.1

這裏有路線。

routes.MapRoute(
    "PagingTwoTest", // Route name 
    "{controller}/{action}/{tag}/p{currentPage}/p{secCurrentPage}/{*term}", // URL with parameters 
    new { secCurrentPage = UrlParameter.Optional, term = UrlParameter.Optional }, // Parameter defaults 
    new { currentPage = "\\d+", secCurrentPage = "\\d+" } 
); 

routes.MapRoute(
    "PagingTwo", // Route name 
    "{controller}/{action}/p{currentPage}/p{secCurrentPage}/{*term}", // URL with parameters 
    new { secCurrentPage = UrlParameter.Optional, term = UrlParameter.Optional }, // Parameter defaults 
    new { currentPage = "\\d+", secCurrentPage = "\\d+" } 
); 

routes.MapRoute(
    "Paging", // Route name 
    "{controller}/{action}/p{currentPage}/{*term}", // URL with parameters 
    new { term = UrlParameter.Optional }, // Parameter defaults 
    new { currentPage = "\\d+" } 
); 

routes.MapRoute(
    "Default", // Route name 
    "{controller}/{action}/{id}", // URL with parameters 
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults 
); 

routes.MapRoute(
    "DefaultName", // Route name 
    "{controller}/{action}/{*id}", // URL with parameters 
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults 
); 

回答

1

在你限制你不考慮當有人進入你永諾要求一個數字的字符串,所以我覺得你可以嘗試用:

routes.MapRoute(
    "TestDetails", // Route name 
    "{controller}/{action}/{id}", // URL with parameters 
    new { 
     controller = "Test", 
     action = "Details", 
     id = UrlParameter.Optional 
    } 
); 

因此,在您的TestController可以請求字符串:

public class TestController : Controller 
{ 
    .... 
    .... 

    public ActionResult Details(string? id) //So you can verify if is null 
    { 
     ViewData["variable"] = id; 
     return View(); 
    } 
    .... 
    .... 
} 

而在你Details.aspx你可以把這樣的事情:

<%@ Page Language="C#" 
    MasterPageFile="~/Views/Shared/Site.Master" 
    Inherits="System.Web.Mvc.ViewPage" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> 
    Title, what you want 
</asp:Content> 

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 
    <p> Blah, blah, blah, you request this: <%: ViewData["variable"] %> </p> 
</asp:Content>