ASP.NETMVC:将HTML表格与其他表单数据一起插入到数据库中
创始人
2024-11-12 05:30:14
0
  1. 首先,我们需要建立一个包含表单和HTML表格的视图。例如:
@model FormModel

@using (Html.BeginForm("InsertData", "ControllerName", FormMethod.Post))
{
    @Html.TextBoxFor(m => m.Name)
    @Html.TextBoxFor(m => m.Email)
    
Column1 Column2
}
  1. 在控制器中,我们需要创建一个名为'InsertData”的动作方法,并使用表单模型类和HTML表格中的数据作为参数。然后可以将它们一起插入到数据库中。例如:
[HttpPost]
public ActionResult InsertData(FormModel formModel, string Column1, string Column2)
{
    // Insert form data and HTML table data into database
    using (var db = new MyDbContext())
    {
        db.FormModels.Add(formModel);
        db.TableData.Add(new TableData 
        {
            Column1 = Column1,
            Column2 = Column2
        });
        db.SaveChanges();
    }

    return View();
}

在上面的例子中,我们使用MyDbContext来插入表单数据和HTML表格数据。

  1. 最后,我们需要在路由中创建一个名为'InsertData”的动作方法。例如:
routes.MapRoute(
    name: "InsertData",
    url: "InsertData/{FormModel}/{Column1}/{Column2}",
    defaults: new { controller = "ControllerName", action = "InsertData" }
);

现在,当我们在视图中输入表单数据和HTML表格数据并单击Submit按钮时,它们将一起插入到数据库中。

相关内容

热门资讯

透视透视!aapoker透视怎... 透视透视!aapoker透视怎么用(透视)免费透视脚本(真是有挂);1、超多福利:超高返利,海量正版...
透视好牌!aapoker破解侠... 透视好牌!aapoker破解侠是真的吗(透视)真的假的(一贯真的有挂)1、完成aapoker破解侠是...
透视辅助!aapoker脚本(... 透视辅助!aapoker脚本(透视)透视脚本下载(本来存在有挂)1、每一步都需要思考,不同水平的挑战...
透视插件!aapoker怎么选... 透视插件!aapoker怎么选牌(透视)ai插件(一贯是真的有挂)一、aapoker怎么选牌AI软件...
透视app!aapoker a... 透视app!aapoker ai插件(透视)透视方法(竟然是真的有挂)所有人都在同一条线上,像星星一...
透视神器!aapoker辅助器... 透视神器!aapoker辅助器是真的吗(透视)透视插件(总是有挂)所有人都在同一条线上,像星星一样排...
透视科技!aapoker怎么设... 透视科技!aapoker怎么设置提高好牌几率(透视)透视方法(一直有挂);1、aapoker怎么设置...
透视教学!aapoker透视脚... 透视教学!aapoker透视脚本(透视)透视脚本(本来是真的有挂)1、让任何用户在无需aapoker...
透视有挂!aapoker怎么提... 透视有挂!aapoker怎么提高中牌率(透视)透视脚本下载(竟然存在有挂)一、aapoker怎么提高...
透视透视!aapoker辅助器... 透视透视!aapoker辅助器是真的吗(透视)透视脚本下载(本来是真的有挂)1)aapoker辅助器...