라우팅 관련 문제가 있습니다. 아래 JavaScript 함수를 사용하여 내 컨트롤러 StudentSearch에 대한 게시물을 작성합니다. 게시물을 만들었을 때 첫 번째 매개 변수 만 전달했습니다. 예상되는 페이지는 null입니다. 그러나 시작 및 종료 날짜에는 날짜 값이 있지만 두 매개 변수는 모두 null입니다. 내가 여기서 무엇을 놓치고 있니? 나는 문서를 읽고 온라인으로 검색하고, 나는 지금까지 성공을 거두지 못했다. 오후 2시 50분에서ASP.NET MVC 4 라우팅 문제
//Javascript function
findStudent function()
{
var SearchValue= $("#Search").val();
var StartDate = $('#StartDate').val();
var EndDate = $('#EndDate').val();
var url = '@Url.Action("Search")';
location.href = url + "/" + SearchValue + "/" + StartDate +"/" + EndDate+;
}
//This is the ActionResult in the controller
public ActionResult Search(string SearchValue, string StartDate , string EndDate)
{
//EndDate and STart Date are null here.
}
//the route section in my RouteConfig.cs file
routes.MapRoute(
name: "Search",
url: "StudentSearch/Search/{SearchValue}/{StartDate}/{EndDate}",
defaults: new { controller = "StudentSearch", action = "Search",
SearchValue = UrlParameter.Optional,StartDate=UrlParameter.Optional,
EndDate = UrlParameter.Optional}
);
갱신 : 크리스 주석을 읽은 후, 나는 코드를 수정했습니다. 그것은 StudentSearch 컨트롤러로 라우팅하지 않았습니다. 대신 404 페이지가 없습니다. 당신이 볼 수 있듯이 Jane에서 searchvalue와 student1, student2는 각각 시작과 종료 날짜로 전달되었습니다 (매개 변수가 문자열로 예상되므로 문제가되지 않았습니다). .../StudentSearch/Search/Jane/student1/student2
나는 싸우고 있었고 왜 작동하지 않는지 알 수 없었다. 업데이트가 필요한 일부 컴퓨터 때문에 컴퓨터를 다시 시작해야했습니다. 응용 프로그램을 다시 실행하고 작동했습니다. – user3802347