2013-04-12 2 views
2

text 상자에 자동으로 생성 된 input 상자가 포함 된보기가 있습니다. "결과 이메일 보내기"버튼을 클릭하면 코드가 CalculatedResults 컨트롤러 내의 EmailResults Action으로 연결됩니다. 여태까지는 그런대로 잘됐다. 그러나 EmailResults Action의 매개 변수로 FormCollection을 가지고 있더라도 null로 처리되므로 이유를 알 수 없습니다. 양식에서 텍스트 상자를 캡처 할 수 있어야합니다. 제발 도와주세요 !!. 아래의 내 View 코드에서 생성 된 텍스트 상자는 중간에서 약간 아래쪽에 있습니다.단추 누름시 텍스트 필드를 FormCollection으로 전달하려고했지만 FormCollection이 null로 처리됩니다.

enter image description here

,691 :

내보기 코드

@using (Html.BeginForm("EmailResults", "CalculatedResults", FormMethod.Post, new { data_ajax = "false" })) 
     { 
      <table> 
       <thead> 
        <tr> 
         <td>Ingredient</td> 
         <td>Qty (gm)</td> 
        </tr> 
       </thead> 
       @foreach (var i in Model) 
       { 
        if (Convert.ToDecimal(i.Qty) < 0) 
        { 
         <tr> 
          <td style="border: 1px solid red; color: red;">@i.Ingredient</td> 
          <td style="border: 1px solid red; color: red;">@i.Qty</td> 
         </tr> 
        } 

        else if (Convert.ToDecimal(i.Qty) == 0m) 
        { 
         continue; 
        } 

        else 
        { 
         if (i.Ingredient.Contains("Active")) 
         { 
         <tr> 
          <td>@i.Ingredient<br /> 
           <input type="text" name="actives" /></td> 
          <td>@i.Qty</td> 
         </tr> 
         } 
         else 
         { 
         <tr> 
          <td>@i.Ingredient</td> 
          <td>@i.Qty</td> 
         </tr> 
         } 
        } 
       } 

      </table> 
     } 
     <div style="float: left"> 
      @Html.ActionLink("Email Results", "EmailResults", "CalculatedResults", new { crpk = @ViewBag.crpk }, new { data_icon = "arrow-r", data_role = "button" }) 
     </div> 

내 컨트롤러 코드 여기

public ViewResult EmailResults(int crpk, FormCollection collection) 
{ 
    CapWorxQuikCapContext context = new CapWorxQuikCapContext(); 

    //List<string> variables = new List<string>(); 
    //foreach (var item in Request.Form) 
    //{ 
    // variables.Add(item.ToString()); 
    //} 

    CalculatedResults cr = (from i in context.CalculatedResults where i.Pk == crpk select i).SingleOrDefault(); 
    Helpers.Email.EmailResults(cr); 

    return View(); 
} 

는 스크린 샷입니다

답변

4

formCollection은 양식을 컨트롤러에 제출할 때만 나타납니다. 어느

  1. 사용 <input type="submit" value="Email Results" />
  2. 와이어까지 당신을 위해 양식을 제출 작성한 ActionLink에 JQuery와 핸들러.
+0

을 통해 경로 값을 보낼 수 있습니까? 내 @ ViewBag.crpk 값을 보낼 수 있어야합니다. –

+1

자바 스크립트를 사용하지 않고 URL을 구성하거나 FormMethod를 GET으로 변경하지 않아도됩니다. 위의 두 가지 옵션 중 하나를 수행해야하지만 POST 대신 경로 값/URL을 통해 수행 할 수 있습니다. – Tommy

관련 문제