2012-04-02 3 views

답변

3

당신이 Html.BeginForm과 같이 사용하는 경우 게시물이 일어날 것입니다 :

[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult HandleForm(MyModel myModel) 
{ 
    // Do whatever you need to here. 

    return RedirectToAction("OtherAction", myModel); 
} 

public ActionResult OtherAction(MyModel myModel) 
{ 
    return View(myModel);  
} 

편집 : : 위 예제

<% using(Html.BeginForm("HandleForm", "Home")) { %> 
    <fieldset> 
     <legend>Fields</legend> 
     <p> 
      <%= Html.TextBoxFor(m => m.Field1) %> 
     </p> 
     <p> 
      <%= Html.TextBoxFor(m => m.Field2) %> 
     </p> 
     <p> 
      <input type="submit" value="Submit" /> 
     </p> 
    </fieldset> 
<% } %> 

이 그런 다음 컨트롤러 액션이 리디렉션을 수행 할 수 있습니다 이제 다음 모델을 사용하여 바인딩하고 작업간에 전달할 수 있습니다.

public class MyModel 
{ 
    public string Field1 { get; set; } 
    public string Field1 { get; set; } 
} 
+0

를 제출 많은 필드를 포함합니다. 입력 개체가 있습니까? –

+0

입력 값을 컨트롤러 동작으로 다시 전달하는 방법을 보여주기 위해 제 대답을 수정했습니다. – CAbbott

1

아래 코드는 사용자가 양식을 제출 한 후 다른 작업으로 리디렉션하는 방법을 보여줍니다.

리디렉션 할 작업 방법에 사용하기 위해 제출 된 데이터를 보존하려면 TempData 개체에 저장해야합니다.

public class HomeController : Controller 
{ 
    [HttpGet] 
    public ActionResult Index() 
    { 
     // Get the e-mail address previously submitted by the user if it 
     // exists, or use an empty string if it doesn't 
     return View(TempData["email"] ?? string.Empty); 
    } 

    [HttpPost] 
    public ActionResult Index(string email) 
    { 
     // Store the e-mail address submitted by the form in TempData 
     TempData["email"] = email; 

     return RedirectToAction("Index"); 
    } 
} 

귀하의 Index보기는 다음과 같이 보일 것입니다 :

@using (Html.BeginForm("Index", "Home")) 
{ 
    @* Will populate the textbox with the previously submitted value, if any *@ 
    <input id="email" type="email" name="email" value="@Model" /> 

    <button type="submit">Submit</button> 
}