【后端C#】mvc 前后端如何传值
2021-01-20 19:12
标签:action using view index return employee auto put member mvc 前后端如何交互数据 4、后端如何传送数据给前端 @{ //action Receiving data from Ajax } //action Receiving data from Form } //action Receiving data from FormCollection 再一种是: 1.用一下代码括住提交的表单区域 @using(Html.BeginForm("AddMemberBaseInfo", "MemberManagement",FormMethod.Post, new { enctype = "multipart/form-data" })) { } 2.js代码 $(document).ready(function () { $(‘form‘).bind(‘submit‘,checkform); }); function checkform() { alert("提交前的验证"); return false; } 3.控制器照常取值 public ActionResult AddMemberBaseInfo() { string memberName=Request.Form["txtMemberName"].ToString(); } 【后端C#】mvc 前后端如何传值 标签:action using view index return employee auto put member 原文地址:https://www.cnblogs.com/BoKeYuan259/p/12121221.html
1、后端如何传送数据给前端
后端:
ViewBag.Message = "Hello " + name;
前端:
@ViewBag.Message
2、后端如何传送数据给前端
后端:
TempData["name"] = "王五";
前端:@TempData["name"]
3、后端如何传送数据给前端
后端:
ViewData["name"] = "王五";
前端:@ViewData["name"]
后端:
PersonViewModel model = new PersonViewModel() { Name="赵六", Age=18};
return View(model);
前端:
@using _06Mvc.Models;
var res = "名称:" + Model.Name + ":" + "年龄:" + Model.Age;
}
5、后端如何传送数据给前端
后端:
List
return View("Index",ltPI);
前端:@using list...
6、后端如何传送数据给前端
后端:return Json(obj,JsonRequestBehavior.AllowGet);
前端:记得好像是数组
7、前端如何给后端传送数据
前端:
location.href ="http://www.soscw.com/JqGridDemo/QueryString/GetParamsFromToView?EmployeeID=NX001&EmployeeName=张三";
后端:
var EmployeeID = Request["EmployeeID"].ToString();
var EmployeeName= Request["EmployeeName"].ToString();
8、前端如何传值给后端
前端:
$.ajax({
url: "/JqGridDemo/AjaxData/GetParamsFromAjax",
type:"GET",
data:{EmployeeID:‘NX001‘,EmployeeName:‘张三‘},
error: function(message) {
alert(‘error!‘);
}
});
后端:
public class AjaxDataController : Controller
{
// GET: JqGridDemo/AjaxData
public ActionResult Index()
{
return View();
}
public void GetParamsFromAjax(string EmployeeID, string EmployeeName)
{
}
9、前端如何传值给后端
后端:
public class FormTransferDataController : Controller
{
// GET: JqGridDemo/FormTransferData
public ActionResult Index()
{
return View();
}
public void GetParamsFromForm(string EmployeeID, string EmployeeName)
{
}
10、前端如何传值给后端
@using (Html.BeginForm("GetParamsFromFormCollection", "FormCollectionTransferData"))
{
@Html.TextBox("EmployeeID","员工ID");
@Html.TextBox("EmployeeName","员工姓名");
}
后端:
public class FormCollectionTransferDataController : Controller
{
// GET: JqGridDemo/FormCollectionTransferData
public ActionResult Index()
{
return View();
}
public void GetParamsFromFormCollection(FormCollection fc)
{
string EmployeeID = fc["EmployeeID"].ToString();
string EmployeeName = fc["EmployeeName"].ToString();
}
}
————————————————
版权声明:本文为CSDN博主「moshengrenhere」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/moshengrenhere/article/details/82697402