[C #] before and after the back-end end mvc how to pass value

How mvc interaction data before and after the end of
a rear end of the front end of how to transmit data to
the rear end:
ViewBag.Message = "the Hello" + name;
front end:
@ ViewBag.Message
2, transmits data to the front end of the rear end of how
  the rear end:
        the TempData [ "name "] =" Wang Wu ";
distal: @TempData [" name "]
. 3, how to transmit data to the front end of the rear end of
the rear end:
the ViewData [" name "] =" Wang Wu ";
distal: @ViewData [" name "]

4, how to transmit data to the front end of the rear end of
the rear end:
 
             PersonViewModel Model new new PersonViewModel = () {the Name = "Zhao six", Age = 18 is};
      return View (Model);
a front end:
@using _06Mvc.Models;

{@
       Var RES = "Name:" + Model.Name + ":" + " Age:" + Model.Age;
        
   }
. 5, the rear end of the front end of how to transmit data to
the backend:
List <the CustomerInfo> = ltPI new new List <the CustomerInfo > ();
return View ( "Index", ltPI);
Front: @using List ...
6, how to send data to the front end of the back-end
back-end: return Json (obj, JsonRequestBehavior.AllowGet) ;
Front: remember like array
7, the front end of how data is transmitted to the rear end
the front end:
the location.href = "/ JqGridDemo / the QueryString / GetParamsFromToView the EmployeeID = NX001 Zhang & EmployeeName =?";
backend:
var the EmployeeID the Request = [ "the EmployeeID"] the ToString ();.
var EmployeeName . the Request = [ "EmployeeName"] the ToString ();
. 8, how to pass values to the rear distal
tip end:
$ .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();
        }

        //action Receiving data from Ajax
        public void GetParamsFromAjax(string EmployeeID, string EmployeeName)
        {

        }
    }
9, how the front end to the rear end of traditional values
 <form action = "/ JqGridDemo / FormTransferData / GetParamsFromForm" method = "get">
        Staff ID: <input type = "text " name = "EmployeeID" />
        Employee Name: < type = INPUT "text" name = "EmployeeName" />
        <INPUT type = "Submit" name = "btnFormTransferData" value = "data transfer form Form1" />
    </ form>
backend:
public class FormTransferDataController: the Controller
    {
        // the GET: JqGridDemo / FormTransferData
        public ActionResult Index ()
        {
            return View ();
        }

        //action Receiving data from Form
        public void GetParamsFromForm(string EmployeeID, string EmployeeName)
        {

        }
    }
10、前端如何传值给后端
<div> 
        @using (Html.BeginForm("GetParamsFromFormCollection", "FormCollectionTransferData"))
        {
            @Html.TextBox("EmployeeID","员工ID");
            @Html.TextBox("EmployeeName","员工姓名");
            <input type="submit" value="FormCollection传值"/>
        }
    </div>
后端:
public class FormCollectionTransferDataController : Controller
    {
        // GET: JqGridDemo/FormCollectionTransferData
        public ActionResult Index()
        {
            return View();
        }

        //action Receiving data from FormCollection
        public void GetParamsFromFormCollection(FormCollection fc)
        {
            string EmployeeID = fc["EmployeeID"].ToString();
            string EmployeeName = fc["EmployeeName"].ToString();
        }
    }

 

Yet another is:

1. Form Click Submit the enclosed area code

    @using(Html.BeginForm("AddMemberBaseInfo", "MemberManagement",FormMethod.Post, new { enctype = "multipart/form-data" }))

    {

        <inputtype="submit" class="buttons1" style="margin:0auto;" value="保存"/>

     <inputtype="text" class="texts" name="txtMemberName" />

     }

2.js Code

    $(document).ready(function () {

            $('form').bind('submit',checkform);

        });

  

        function checkform() {

            alert ( "verification before submission");

            return false;

        }

3. Controller usual values

   public ActionResult AddMemberBaseInfo()

    {

          string memberName=Request.Form["txtMemberName"].ToString();

    }
----------------
Disclaimer: This article is CSDN blogger "moshengrenhere 'original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source and this link statement.
Original link: https: //blog.csdn.net/moshengrenhere/article/details/82697402

Guess you like

Origin www.cnblogs.com/BoKeYuan259/p/12121221.html