84°

C#-.NetMVC基本传参

1.Controller->View

public ActionResult Index()
        {
            ViewBag.Name = "Hello World!";
            ViewData["Name"] = "Hello World!";
        List<string> items = new List<string>
        {
            "hello","world","test"
        };

        return View(items);
    }</code></pre> 
@model List<string>
@ViewBag.Name
@ViewData["Name"]
@foreach (string item in Model)
{
    @Html.DisplayFor(model => item);
}

2.View ->Controller

<form action="/Home/About">
     姓名:<input type="text" name="name"><br>
     地址:<input type="text" name="address"><br>
     <input type="submit" value="提交">
</form>
public String About(string name,string address,Stu s)
        {
            string name_ = Request["name"];
            string address_ = Request["address"];
        return name_ + address_;
    }</code></pre> 

 

本文由【愚蠢的土豆】发布于开源中国,原文链接:https://my.oschina.net/stupidpotato/blog/3158065

全部评论: 0

    我有话说: