我想创建一个带有值 的HTML表单提交按钮'add tag'
,但是,网页是瑞典语,所以我想要一个不同的按钮文本.
也就是说,我想要一个按钮
但我想让我的代码像
if (request.getParameter(cmd).equals("add tag"))
tags.addTag( /*...*/ );
Run Code Online (Sandbox Code Playgroud)
这可能吗?如果是这样,怎么样?
我的MVC表单上有两个按钮:
<input name="submit" type="submit" id="submit" value="Save" />
<input name="process" type="submit" id="process" value="Process" />
Run Code Online (Sandbox Code Playgroud)
从我的Controller动作我怎么知道哪一个被按下了?
Razor视图在表单中有3个按钮.所有按钮的操作都需要表单值,这些值基本上是输入字段的值.
每次我点击任何按钮时,它都会将我重定向到默认操作.您能否指导我如何根据按钮提交表单到不同的操作?
我非常感谢您的时间,指导和帮助.
我在用ASP.Net MVC 4
.我在视图上有多个按钮..目前我调用相同的动作方法; 我正在区分使用name
属性的单击按钮.
@using (Html.BeginForm("Submit", "SearchDisplay", new { id = Model == null ? Guid.NewGuid().ToString() : Model.SavedSearch }, FormMethod.Post))
{
<div class="leftSideDiv">
<input type="submit" id="btnExport" class="exporttoexcelButton"
name="Command" value="Export to Excel" />
</div>
<div class="pageWrapperForSearchSubmit">
<input type="submit" class="submitButton"
value="Submit" id="btnSubmitChange" />
</div>
}
Run Code Online (Sandbox Code Playgroud)
//行动
[HttpPost]
public ActionResult Submit(SearchCostPage searchModel, string Command)
{
SessionHelper.ProjectCase = searchModel.ProjectCaseNumber;
if (string.Equals(Command, Constants.SearchPage.ExportToExcel))
{
}
}
Run Code Online (Sandbox Code Playgroud)
质询
参考文献:
我需要多个提交按钮来在控制器中执行不同的操作.
我在这里看到了一个优雅的解决方案:如何在ASP.NET MVC Framework中处理多个提交按钮? 使用此解决方案,可以使用自定义属性修饰操作方法.处理路径时,此自定义属性的方法检查属性的属性是否与单击的提交按钮的名称匹配.
但是在MVC Core(RC2 nightly build)中我还没有找到ActionNameSelectorAttribute
(我还搜索了Github存储库).我发现了一个类似的解决方案ActionMethodSelectorAttribute
(http://www.dotnetcurry.com/aspnet-mvc/724/handle-multiple-submit-buttons-aspnet-mvc-action-methods).
ActionMethodSelectorAttribute
可用,但该方法IsValidForRequest
具有不同的签名.有一个类型的参数RouteContext
.但我找不到那里的帖子数据.所以我没有什么可以与我的自定义属性属性进行比较.
MVC Core中是否有与之前MVC版本类似的优雅解决方案?
我收到以下错误:
Child actions are not allowed to perform redirect actions.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Child actions are not allowed to perform redirect actions.
Source Error:
Line 1: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<RenderActionViewModel>" %>
Line 2: <%Html.RenderAction(Model.ActionName, Model.ControllerName, Model.RouteValues); %>
Line 3:
The Stack trace is:
[InvalidOperationException: Child actions are not allowed …
Run Code Online (Sandbox Code Playgroud) 考虑以下标记:
<h2>Edit SAS Program</h2>
@using (Html.BeginForm("Edit", "SasProgram", FormMethod.Post))
{
<label for="Name">Name</label>
@Html.TextBoxFor(model => model.Name)
using (Html.BeginForm("Delete", "SasProgram", FormMethod.Post))
{
<input type="submit" class="button" value="Delete" />
}
<input type="submit" class="button" value="Save Changes" />
}
Run Code Online (Sandbox Code Playgroud)
我想把Delete
按钮放在与...相同的视图上Edit
.但是,它不会让我有嵌套的表单.处理这种情况的适当方法是什么?
我尝试利用这个答案,如何处理ASP.NET MVC中的嵌套表单,但现在它已经是一个断开的链接.
我正在使用带有Razor引擎的ASP.net MVC 4.
我有一个页面(Index.cshtml)和一个控制器(HomeController.cs)
我试图将我的提交按钮连接到我的控制器中的动作结果 - 但是我似乎无法解决它.
我的HTML:
@using (Html.BeginForm("SubmitForm", "Home", FormMethod.Post))
{
<div class="main-Background">
******lots of other html here*******
<button type="submit" id="btnSave">Save</button>
</div>
}
Run Code Online (Sandbox Code Playgroud)
我的控制器:
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
return View();
}
public ActionResult About()
{
ViewBag.Message = "Your app description page.";
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
[HttpPost]
public ActionResult SubmitForm()
{ …
Run Code Online (Sandbox Code Playgroud) 我按照这篇文章的说明: Asp.net mvc3 razor有多个提交按钮 ,这是我的模型:
public class AdminModel
{
public string Command { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的控制器
[HttpPost]
public ActionResult Admin(List<AdminModel> model)
{
string s = model.Command;
}
Run Code Online (Sandbox Code Playgroud)
我的看法
@using (Html.BeginForm("Admin", "Account"))
{
<input type="submit" name="Command" value="Deactivate"/>
<input type="submit" name="Command" value="Delete"/>
}
Run Code Online (Sandbox Code Playgroud)
当我回发时,字符串"s"始终为空.
我在这个论坛帖子中尝试了第二个答案(146票的答案):你如何处理ASP.NET MVC框架中的多个提交按钮?那也是空的.我究竟做错了什么?
我在MVC4中面对我的JQuery移动APP上的一个奇怪的问题:
我有一个像这样的几个texbox的表单
@using Models
@model Models.DataModel.Pagina_Details
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm("Pagina_Details", "Home", FormMethod.Post, new { id = "PaginaDetailsForm" }))
{
if (Request.QueryString["Command"] != null)
{
Session["Command"] = Request.QueryString["Command"];
}
else
{
Response.Redirect("Index");
}
<div class="ui-corner-all custom-corners ui-shadow">
<div class="ui-bar ui-bar-a">
<h3>Pagina's</h3>
</div>
<div class="ui-body ui-body-a">
<input type="hidden" id="Command" />
@Html.HiddenFor(model => model.ID)
@Html.LabelFor(model => model.Name, "Naam *", new { @class = "lbl"})
@Html.TextBoxFor(model => model.Name, new { required = "required" })
@Html.LabelFor(model => model.Description, "Omschrijving *", new { …
Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×8
c# ×7
asp.net ×4
razor ×3
forms ×2
.net ×1
asp.net-core ×1
html ×1
security ×1
submit ×1