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按钮时,它们将一起插入到数据库中。

相关内容

热门资讯

透视工具!wejoker黑侠辅... 透视工具!wejoker黑侠辅助器(透视)wepoker有没有机器人(竟然一直都是有挂)-哔哩哔哩1...
透视神器!hhpoker辅助挂... 透视神器!hhpoker辅助挂(透视)hhpoker到底可以作必弊码(原来一直总是有挂)-哔哩哔哩1...
透视神器!模拟器打开hhpok... 透视神器!模拟器打开hhpoker(透视)hhpoker免费透视脚本(切实有透视)-哔哩哔哩1、首先...
透视攻略!hh poker软件... 透视攻略!hh poker软件(透视)hhpoker德州机器人(原来一直总是有透视)-哔哩哔哩1、很...
透视软件!潮汕激k辅助(辅助)... 透视软件!潮汕激k辅助(辅助)新九五辅助微信脚本(其实存在有挂)-哔哩哔哩一、新九五辅助微信脚本可以...
透视脚本!aapoker脚本怎... 透视脚本!aapoker脚本怎么用(透视)aapoker怎么拿好牌(一贯一直都是有透视)-哔哩哔哩1...
透视攻略!hhpoker到底可... 透视攻略!hhpoker到底可以作必弊码(透视)德扑HHpoker有挂吗(一贯一直总是有辅助器)-哔...
透视app!德州透视插件(透视... 透视app!德州透视插件(透视)hhpoker辅助器(真是有透视)-哔哩哔哩1、在德州透视插件插件功...
透视攻略!拱趴大菠萝有挂吗(透... 透视攻略!拱趴大菠萝有挂吗(透视)pokemmo手机版透视脚本(总是是有辅助器)-哔哩哔哩1、不需要...
透视脚本!欢聚水鱼脚本(辅助)... 您好,jj斗地主捕鱼辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多...