将表格发布到其他控制器

时间:2016-03-28 10:11:50

标签: c# asp.net asp.net-mvc asp.net-core-mvc

我有一个HomeController用于登陆页面(主页,关于,联系我们),在家庭视图中我注册了两种类型(2个独立的视图模型)和登录(另一个视图模型)。我想知道是否有一种从索引视图(HomeController)将表单发布到另一个控制器的方法。我试图用标签帮助器来做这件事,但似乎它不起作用。这是我的代码,我试图这样做

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

这是我在员工控制器中的注册操作

 [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);
    }

感谢您的帮助

2 个答案:

答案 0 :(得分:3)

使用剃刀语法Stream<MyType> stream = // get the stream from somewhere List<MyType> list = stream.collect(Collectors.toList()); // materialize the stream contents list.stream().doSomething // create a new stream from the list list.stream().doSomethingElse // create one more stream from the list

Html.BeginForm

enter image description here

或者在纯HTML中执行此操作

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

}

答案 1 :(得分:2)

@using (Html.BeginForm("Register", "YourController", FormMethod.Post, null))
    {
        <input type="submit" value="Html PsBk Click" />
    }