2016-03-28 37 views
0

私は2つのタイプ(2つの個別のビューモデル)とログイン(別のビューモデル)の登録を持っています。インデックスビュー(HomeController)から別のコントローラにフォームをポストする方法があるかどうかを知るために、私はタグヘルパーでこれをやろうとしていますが、うまくいかないようです。私はこの他のコントローラへのフォームの投稿

<form asp-controller="Employee" asp-action="Register" method="post" role="form" class="ui large form"> 
.... 
</form> 

とここをやろうとしているHere`s私のコードは、ヘルプ

+1

は{...} 'あなたのASPを変更 –

+0

' @using(Html.BeginForm( "アクション"、 "コントローラ"、FormMethod.Post))してみます-action to asp-action = "登録/登録" – Rex

答えて

2

ため

[HttpPost] 
    [AllowAnonymous] 
    [ValidateAntiForgeryToken] 
    public async Task<IActionResult> Register(EmployeeRegisterViewModel employeeRegisterModel) 
    { 
     if (ModelState.IsValid) 
     { 
      IdentityResult result = await _service.CreateEmployeeAccount(employeeRegisterModel); 
      if (result.Succeeded) 
      { 
       return RedirectToAction(nameof(EmployeeController.Index), "Employee"); 
      } 
      AddErrors(result); 
     } 

     return View(employeeRegisterModel); 
    } 

おかげでかみそりの構文を使用する従業員コントローラの私の登録アクションですHtml.BeginForm

@using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post, new { @class = "ui large form"})) 
{ 

} 

enter image description here

またはプレーンHTMLでこの

<form action="/ControllerName/ActionName" asp-action="Register" method="post" role="form" class="ui large form"> 
.... 
</form> 
1
@using (Html.BeginForm("Register", "YourController", FormMethod.Post, null)) 
    { 
     <input type="submit" value="Html PsBk Click" /> 
    } 
関連する問題