【问题标题】:Correlation between submit and beginform提交和beginform之间的相关性
【发布时间】:2013-05-21 14:55:51
【问题描述】:

尝试在视图中渲染多个模型时遇到问题。

假设我有:

型号

public int ID { get; set; }
public ArrayOfThings[] Things { get; set; }

查看

for (int i = 0; Model.Things.Count() > i; i++)
{
    using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { Id = i }))
    {
        <p>@Html.CheckBoxFor(m => m.Things[i].IsDone, "Some Check")</p>

        <input type="submit" title="Delete" value="Check as Done" name="btn_submit" />
    }
}

我将如何做到这一点,以便输入(提交)按钮与正确的表单相关联?事实上,只有第一种形式受到影响。

【问题讨论】:

  • 谢谢,但这似乎不起作用
  • this question from Friday。不幸的是,我目前不知道如何使用多种表单进行这项工作,但这应该可以为您提供一个起点。
  • 查看这些帖子:- [ASP.NET MVC 3 一个表单中的多个提交输入][1] - [如何处理 ASP.NET MVC 框架中的多个提交按钮?][2] [ 1]:stackoverflow.com/questions/8258750/… [2]:stackoverflow.com/questions/442704/…
  • 从您的问题中不清楚您是有多个表格还是一个表格。此外,在提交此表单时,您希望将什么模型发布到服务器也不清楚。另外你为什么将id 设置为循环的索引?

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


【解决方案1】:

我认为也许你需要改变主意。 为什么要创建新表格? 您可以使用操作链接代替提交按钮,并通过 ActionLink 参数发送数据。

  <%=Html.ActionLink("Link Text", "Action", "Controller", new {id = "1"}, null)%>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-09
    • 2017-09-28
    • 2023-03-18
    • 1970-01-01
    • 2014-02-09
    • 1970-01-01
    • 2019-11-03
    • 1970-01-01
    相关资源
    最近更新 更多