2012-04-23 2 views
2

Html.EditorFor에서 myController의 myAction으로 데이터를 전달하는 방법은 무엇입니까? 난 내 편집기와 같은 이름의 매개 변수가하려고했지만 그 작동하지 않았다, 여기Html.EditorFor에서 컨트롤러로 데이터 전달

public ActionResult SaveQuote(FxQuote quote, string Quote_Currency) 
     { 


       objQuote.Quote_Currency = Quote_Currency; 

       dcfx.FxQuotes.InsertOnSubmit(quote); 
       dcfx.SubmitChanges(); 


      return View(); 

:

<div class="editor-label"> 
      @Html.LabelFor(model => model.Quote_Currency) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.Quote_Currency, new { }) 
      @Html.ValidationMessageFor(model => model.Quote_Currency) 
     </div> 

이 내 컨트롤러 액션입니다 :

내 편집기입니다 . 도와주세요.

+2

는'

에인가하는 데 도움이 : 다른 답변에서 언급 한 바와 같이

public ActionResult SaveQuote(ModelType model) { objQuote.Quote_Currency = model.Quote_Currency; dcfx.FxQuotes.InsertOnSubmit(model.Quote); dcfx.SubmitChanges(); return View(); } 

가 또는 폼 수집을 받아 변경할 수 있습니다 '? POST 요청에서 무엇을 볼 수 있습니까? – SLaks

+1

모델은 어떤 유형입니까? – Xharze

+0

편집기는 (Html.BeginForm) 형식으로되어 있습니다. LINQ를 사용하고 있습니다. – Bree

답변

1

FormCollection collection을 추가 매개 변수로 컨트롤러 메서드에 추가 할 수 있습니다. 이 컬렉션은 컨트롤러의 뷰에서 전달 된 모든 데이터를 보유합니다. 디버거를 사용하여 정확히 어떤 데이터가 컨트롤러로 전송되는지 탐색 할 수 있습니다.

0

왜 모델을 수락하기 위해 동작을 변경하지 않습니까? 이 같은

뭔가 :

public ActionResult SaveQuote(FormCollection collection) 

는 희망이

관련 문제