【发布时间】:2015-04-16 14:56:37
【问题描述】:
我是 MVC 的新手。我有一个“创建”按钮。我想在我的控制器中创建另一个调用“部署”操作的按钮。这个按钮基本上是提交表单并被部署。目前,表单已提交,但代码未进入“部署”功能
这是我尝试过的:-
<input type="submit" class="btn btn-primary" value="Create" />
<input type="submit" class="btn btn-primary" value="Create and deploy" onclick="location.href='@Url.Action("Deploy", "MyController")' "/>
我的 Deploy 函数需要一个类似这样的参数:-
<a href="@Url.Action("Deploy", new {Id = Model.Id })">Deploy</a>
编辑
这就是我的代码现在的样子:-
@using (Html.BeginForm("Create", "MyController", FormMethod.Post, new { data_bind = "submit: formSubmit" }))
{
<input type="submit" name ="create" class="btn btn-primary" value="Create" />
<input type="submit" name="create" class="btn btn-primary" value="Create and deploy"/>
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(MyModel entity, string submitType)
{
if (submitType == Create and Deploy)
{
RedirectToAction("Deploy", "MyController");
}
//Code to create
}
public ActionResult Deploy(string Id)
{
}
我该如何解决这个问题?
【问题讨论】:
-
@StephenMuecke 感谢您的回复。你能详细说明你的答案吗?
-
@StephenMuecke 我做到了。仍然给我相同的输出。我已经编辑了我的问题,我还需要将参数传递给 Deploy 函数。我想它不起作用,因为我没有通过它。你能帮我解决这个问题吗
-
@StephenMuecke 很抱歉造成混淆,我已将我的编辑放在问题中。你现在可以检查吗?我得到了 submitType =null
-
@StephenMuecke 我想做提交和部署。使用 @Html.ActionLink("Deploy", "Guage", new { Id = Model.ID }) 不会直接部署吗?
-
@StephenMuecke 基本上我有两个按钮 1) 创建 2) 创建和部署。在创建表单时应该只提交而不是部署。随着创建和部署表单应该提交并部署。
标签: jquery html asp.net-mvc-4