2013-07-25 4 views
0

저는 MVC를 처음 사용합니다.레이아웃에서 컨트롤러 호출

나는 내 레이아웃 페이지에 다음과 같습니다

<div id="RunValidation"> 
     @using (Html.BeginForm("RunValidation", "Home")) 
     { 
      <table> 
       <tr> 
        <td> 
         <input type="checkbox" name="chkFindDuplicates" value="chkFindDuplicates">Find Cards 
        </td> 
       </tr> 

       <tr> 
        <td> 
         <input type="checkbox" name="chkFindDuplicates" value="chkFindDuplicates">Find Duplicates 
        </td> 
       </tr> 

       <tr> 
        <td> 
         <input type="checkbox" name="chkFindSuspectVoucherAllocation" value="chkFindSuspectVoucherAllocation">Find Suspect Voucher Allocataion 
        </td> 
       </tr> 


       <tr> 
        <td></td> 
        <td> 
         <input type="submit" value="SubmitValidation" /></td> 
       </tr> 
      </table> 
     } 
    </div> 

내 HomeController에서 다음과 같은 조치 한 다음

public ActionResult RunValidaton() 
    { 
     //determine which validations checks to run 
     int x = 0; 


     //call into middle tier to execute the validation 

     return View(); 

    } 

내 경로 설정이되어 같이

public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

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

내 HTML 양식에 제출 단추를 클릭하면 int x = 0에서 중단 점을 맞추기를 바라고 있습니다. 컨트롤러에서 줄을 찾았지만 404 오류가 발생합니다. 나는 포스트 헤더에 다음 볼 수 있습니다 피들러에서

:

POST /Home/RunValidation HTTP/1.1 

요청이 컨트롤러에 전달되지 않는 이유를 이해할 수 없다?

답변

2

시도해보십시오.

조치 방법 이름을 변경하십시오. 아래 코드를 참조하십시오

<div id="RunValidation"> 
     @using (Html.BeginForm("Jeet", "Home", FormMethod.Post)) 
     { 
      <table> 
       <tr> 
        <td> 
         <input type="checkbox" name="chkFindDuplicates" value="chkFindDuplicates">Find Cards 
        </td> 
       </tr> 

       <tr> 
        <td> 
         <input type="checkbox" name="chkFindDuplicates" value="chkFindDuplicates">Find Duplicates 
        </td> 
       </tr> 

       <tr> 
        <td> 
         <input type="checkbox" name="chkFindSuspectVoucherAllocation" value="chkFindSuspectVoucherAllocation">Find Suspect Voucher Allocataion 
        </td> 
       </tr> 


       <tr> 
        <td></td> 
        <td> 
         <input type="submit" value="SubmitValidation" /></td> 
       </tr> 
      </table> 
     } 
    </div> 

    [HttpPost] 
     public ActionResult Jeet() 
     { 

      //determine which validations checks to run 
      int x = 0; 


      //call into middle tier to execute the validation 

      return View(); 

     } 


routes.MapRoute(
      name: "DefaultRunValidation", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "Dashboard", action = "Jeet", id = UrlParameter.Optional } 
     ); 
+0

이 변경을 시도하고 웹 사이트를 시작했을 때 HTTP 오류 403.14 - 금지 됨 –

+0

이 코드를 업데이트했습니다. –

+0

예, 작동했습니다! 고마워. –

0

http 메서드 표기 및 동작 매개 변수를 사용하여 작업을 생성하십시오.

[HttpPost] 
public ActionResult RunValidaton(FormCollection form) //your model here would be better. 
    { 
     //determine which validations checks to run 
     int x = 0; 


     //call into middle tier to execute the validation 

     return View(); 

    } 
+0

나는 이것이 영향을 미치지 않을까 걱정된다. –