2013-01-16 2 views
0

텍스트를 입력하고 나중에 제출하기 위해 Html.TextBoxFor를 사용하고 있습니다. 내가 원했던 것은 예외/오류의 경우 제출시 사용자가 이전에 입력 한 값을 사용하여 양식보기 으로 돌아가는 것입니다.오류/예외시 양식 값 유지

내 POST 액션 :

[HttpPost] 
public ActionResults Add(Model model) 
{ 
    try 
    { 
     //on succeed 
     _repository.Add(model); 
     return RedirectToAction("ThankYou", "Home"); 
    } 
    catch(Exception ex) 
    { 
     ModelState.AddModelError('foo', ex.Message); 
    } 

    return View(model); 
} 

보기 코드 :

<div class="origin"> 
       <div class="float-left margin-right"> 
        @Html.LabelFor(m => m.From, "From:", new { @class = "block-display" }) 
        @Html.TextBoxFor(m => m.From, new 
         { 
          type = "text", 
          @class = "airport-auto-complete", 
          auto_complete = "", 
          placeholder = "enter place or airport", 
          ng_model = "From" 
         }) 
       </div> 
       <div class="float-left"> 
        @Html.LabelFor(m => m.DepartAt, "Depart:", new { @class = "block-display" }) 
        @Html.TextBoxFor(m => m.DepartAt, new 
         { 
          type = "text", 
          @class = "begin-trip-date date-input", 
          ng_model = "DepartAt" 
         }) 
        <input type="button" class="more-options-btn" value="More.." /> 
        <input type="button" class="transport-btn" /> 
       </div> 
       <br style="clear: left;" /> 
      </div> 
      <div class="more-details"> 
       <div> 
        <label> 
         <input type="checkbox" id="allow-via" /> 
         Allow nearby</label> 
        <br /> 
       </div> 
       <div> 
        <label for="via" class="block-display">Via:</label><input type="text" id="via" auto-complete /> 
       </div> 
       <div> 
        <div class="float-left left"> 
         <label for="flight-num" class="block-display">Flight No.:</label><input type="text" id="flight-num" /> 
        </div> 
        <div class="float-left"> 
         <label for="stops" class="block-display">Stops:</label><input type="text" id="stops" /> 
        </div> 
       </div> 
      </div> 
      <div class="destination"> 
       <div class="float-left margin-right"> 
        @Html.LabelFor(m => m.To, "To:", new { @class = "block-display" }) 
        @Html.TextBoxFor(m => m.To, new 
       { 
        type = "text", 
        @class = "airport-auto-complete", 
        auto_complete = "", 
        placeholder = "enter place or airport", 
        ng_model = "To" 
       }) 
       </div> 
       <div class="float-left"> 
        @Html.LabelFor(m => m.ReturnAt, "Return:", new { @class = "block-display" }) 
        @Html.TextBoxFor(m => m.ReturnAt, new 
       { 
        type = "text", 
        @class = "end-trip-date date-input", 
        ng_model = "ReturnAt" 
       }) 
       </div> 
       <br style="clear: left;" /> 
      </div> 
+1

. 그게 다 뭐니? – Dismissile

+1

보기 코드도 공유 할 수 있습니까? 당신이 Html.TextBoxFor 대신 Html.TextBox를 사용하지 않는 한 당신이 거기에있는 코드처럼 보입니다. –

+0

@AlexMoore보기 코드 –

답변

0

ng_model = "To" 속성이 문제의 원인임을 밝혀졌습니다. ng-model은 클라이언트 측 데이터 바인딩을 처리하고이 범위에 데이터가 없기 때문에 AngularJs 프레임 워크의 기본 제공 지시문입니다. 당신은 약 읽을 수

은 여기에 있습니다 : 그것은 지금처럼이 코드는 정확하게 당신이 원하는 일을 할 것으로 보인다 ngModel