MVC使操作链接进行提交 [英] MVC make action link perform a submit
问题描述
我目前正在做一个HTML提交发生,但使用MVC的辅助方法ActionLink的,因为我不希望它成为一个按钮,我希望它像我的网页上休息下划线的链接。这是我目前有
I am currently trying to make an html submit occur, but using the MVC helper method ActionLink as I do not want it to be a button, I want it to be an underlined link like the rest on my page. This is what I have currently
<%= Html.ActionLink("Delete Selected", "DeleteCheckBox", "Domains", "Default.aspx", new { type="submit" }) %>
这跳回到我的行动很好,但所有被勾掉要删除的域不送回。 (如果我用这个,&LT;输入类型=提交名称=DeleteActionVALUE =删除/&GT;
它工作得很好,所以我知道这不是什么问题在提交或检索复选框)
This jumps back to my action fine, but all the domains that are checked off to be deleted are not sent back. (if I use this, <input type="submit" name="DeleteAction" value="Delete" />
it works fine so I know it's not something wrong with submitting or retrieving the check boxes)
这是我迄今为止...
Here's what I have so far ...
&LT;%@页标题=LANGUAGE =C#的MasterPageFile =〜/查看/共享/的Site.Master继承=System.Web.Mvc.ViewPage>%>
&LT;%@导入命名空间=IProwlAdminUI.Helpers%>
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage>" %> <%@ Import Namespace="IProwlAdminUI.Helpers" %>
指数
Index
<h2>Domain List</h2>
<h2 style="color: #FF0000"><%= Html.Encode(ViewData[IProwlAdminUI.Utils.Global.ExceptionMessageKey]) %></h2>
<h2 style="color: #FF0000"><%= Html.Encode(ViewData["Message"]) %></h2>
<% using (Html.BeginForm("DeleteCheckBox", "Domains"))
{ %>
<% if (ViewData.ContainsKey("DeleteMessage"))
{ %>
<h2 style="color: #FF0000"><%= Html.Encode(ViewData["DeleteMessage"]) %></h2>
<input type="submit" name="DeleteAction" value="Commit" /> <input type="reset" name="DeleteAction" value="Cancel" />
<% } %>
<p>
<%= Html.ActionLink("Create New", "Create") %>
| <%= Html.ActionLink("Export List", "Export") %>
| **<a href="javascript:void(0)" class="DeleteLink">Delete Selected</a>**
<% if (ViewData.ContainsKey("Path"))
{ %>
| <%= Html.ReferenceToFile("/download/Domains.xls", "Exported File") %>
<% } %>
</p>
<div style="overflow:scroll; width:100%">
<% Html.Telerik().Grid(Model).Name("Domains")
.DataKeys(dataKeys => dataKeys.Add(c => c.DomainId)).DataKeys(dataKeys => dataKeys.Add(c => c.Name))
.Columns(columns =>
{
columns.Template(o =>
{ %>
<%= Html.ActionLink("Edit", "Edit", new { id = o.DomainId })%>
<%
}).Title("Edit");
columns.Template(o =>
{ %>
<% if (ViewData.ContainsKey("DeleteMessage"))
{ %>
<input type='checkbox' checked="checked" id='<%= o.Name %>' name='DeleteIds' value='<%= o.DomainId %>' />
<% } %>
<% else
{ %>
<input type='checkbox' id='<%= o.Name %>' name='DeleteIds' value='<%= o.DomainId %>' />
<% } %>
<%
}).Title("Delete");
columns.Bound(o => o.DomainId);
columns.Bound(o => o.Name);
columns.Bound(o => o.SiteId);
columns.Bound(o => o.ScrubAndRedirect);
columns.Bound(o => o.ReportingSiteId);
columns.Bound(o => o.TrafficCopClass);
columns.Bound(o => o.SiteName);
columns.Bound(o => o.FeedType);
columns.Bound(o => o.Active);
}).Sortable().Filterable().DataBinding(db => db.Server().Select("Index", "Domains")).Render();%>
</div>
<% if (!ViewData.ContainsKey("DeleteMessage"))
{ %>
<input type="submit" name="DeleteAction" value="Delete" />
<% } %>
<% } %>
<p>
<%= Html.ActionLink("Create New", "Create") %> | <%= Html.ActionLink("Export List", "Export") %>
<% if (ViewData.ContainsKey("Path"))
{ %>
| <%= Html.ReferenceToFile("/download/Domains.xls", "Exported File") %>
<% } %>
</p>
**<script type="text/javascript">
$(function() {
$('.DeleteLink').click(function() {
$(this).closest('form')[0].submit();
});
});
</script>**
推荐答案
您不能使一个超链接提交表单没有JavaScript。
You cannot make a hyperlink submit a form without Javascript.
使用jQuery,你可以写
Using jQuery, you can write
<a href="javascript:void(0)" class="DeleteLink">Delete Selected</a>
$('.DeleteLink').click(function() {
$(this).closest('form')[0].submit();
});
这篇关于MVC使操作链接进行提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!