사용자에게 시작 우편 번호를 입력하고 버튼을 누르고 알려진 우편 번호로 운전 경로를 제공하는 페이지에서 양식을 제공하려고하는 중입니다.MVC @ Html.BeginForm 잘못된 경로와 일치합니다.
routes.MapRoute("Directions", "Directions/{Name}/{StartPostCode}-to-{DestinationPostCode}", new { controller = "Directions", action = "Index" });
내가 양식을 제출하려면 다음 코드를 사용하고 있습니다 :
내가 일치 할 경로는 다음과 같이 정의된다
@using (@Html.BeginForm("Index", "Directions", new { DestinationPostCode = Model.postcode, Name = Model.nameURLized }, FormMethod.Get))
{
<input type="text" name="StartPostCode" id="StartPostCode" class="inputGreyed" value="Enter Postcode" onclick="ToggleDefaultText(this)"/>
<input type="submit" value="Get Directions" />
}
문제는 내가 /Directions/Index?StartPostCode=abc123
에 끝날 것입니다. 대상 우편 번호와 이름 키 값 쌍이 누락되었습니다. 이것은 물론 내가 잘못된 요청으로 처리된다는 것을 의미합니다. Phil Haacks 경로 디버거를 사용하여이 사실을 입증했습니다.
예상대로 작동하는 /Directions/TheName/ABC123-to-DT83PX
으로 직접 이동했는지 테스트했습니다. 사실, 다음 코드를 사용하여 링크를 만들었습니다.
@Html.ActionLink("Directions Generated", "Index", "Directions", new { StartPostCode = "ABC123", DestinationPostCode = Model.postcode, Name = Model.nameURLized }, new { @class = "button", @title = "More details on " + Model.name })
도움이 될만한 정보가 있습니다.