.NET Core 中MVC專案
阿新 • • 發佈:2021-06-29
後臺傳值前臺的方式:
第 一種:後臺:ViewData["shan"] 前臺: @ ViewData["shan"]
第 二種:後臺:ViewBag.shan 前臺:@ ViewBag.shan
第三種:後臺:1、List<UserTable>2、return View(list);前臺:1、抬頭定義@model List<UserTable>和定義using控制器的名稱@using WebApplication1.Controllers 2、標籤中使用@Model[0].Sex;
第四種:後臺:usertable c=new usertable{name=山東,id=1} 前臺:1、抬頭定義using表類的名稱@model WebApplication1.Controllers 2、標籤中使用@Model[0].Sex
前臺傳值後臺的方式:
第一種:<from action="saysth "
method="post"
></from>繫結的是表的實體類,後臺對實體類操作,
第二種:<from action="Home/index "
method="post"
></from>繫結的是控制器下面的方法,後臺方法裡要定義接受引數的名稱
第三種:@using (Html.BeginForm("styse", "tow"))//styse是控制器下的方法名稱,tow控制器名稱{<input type="text" name="sex" id="sex" /> <input type="submit" value="提交" />}