gpt4 book ai didi

c# - MVC 使操作链接执行提交

转载 作者:太空狗 更新时间:2023-10-29 18:33:20 25 4
gpt4 key购买 nike

我目前正在尝试进行 html 提交,但使用 MVC 辅助方法 ActionLink,因为我不希望它是一个按钮,我希望它是一个带下划线的链接,就像我页面上的其他链接一样。这是我目前拥有的

<%= Html.ActionLink("Delete Selected", "DeleteCheckBox", "Domains", "Default.aspx", new { type="submit" }) %>

这可以很好地跳回我的操作,但不会发回所有选中要删除的域。 (如果我使用它,<input type="submit" name="DeleteAction" value="Delete" /> 它工作正常,所以我知道提交或检索复选框没有问题)

这是我目前所拥有的......

>"%>

指数

<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,您无法创建超链接提交表单。

使用jQuery,你可以写

<a href="javascript:void(0)" class="DeleteLink">Delete Selected</a>

$('.DeleteLink').click(function() { 
$(this).closest('form')[0].submit();
});

关于c# - MVC 使操作链接执行提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3449807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com