4

MVC 5.1 프로젝트가 있고 속성 라우팅을 사용하고 있습니다. 로그인 양식이있는 기본 페이지를 제외한 모든 항목이 정상적으로 작동합니다. 방법이MVC 속성 라우팅 - GET 및 POST가있는 기본 컨트롤러 색인

당신은 표시 할 수 없습니다 찾고있는 페이지 허용되지 않음 -

[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) 

양식은

HTTP 오류 405.0 ... 가져 오기 미세 통해하지만 우리가 얻을 POST에 표시됩니다 유효하지 않은 메서드 (HTTP 동사)가 사용 중이기 때문입니다.

일반적으로 기본 경로는 POST와 GET을 모두 처리합니다.

routes.MapRoute(
     name: "Default", 
     url: "{controller}/{action}/{id}/{dealerId}", 
     defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
    ); 

분명히 다른 페이지의 후속 게시물이 제대로 작동하므로 기본 경로의 게시물 라우팅에 여기에 뭔가 빠져 있습니다.

누구에게이 작업을 수행 했습니까?

덕분에,

답변

9

좋아 정말

[Route("~/")] 
[Route] 
[Route("Index")] 
[HttpPost] 
[ValidateAntiForgeryToken] 

public ActionResult Index(String Username, String Password) 

명백한 추가되어 내가해야 할 모든 것! 긴 하루!