Asp.Net Mvc 简单传值

路由器:

 public class SubInfoController : Controller
    {
        //
        // GET: /SubInfo/

        /// <summary>
        /// 传值路由(初始化界面)
        /// </summary>
        /// <returns></returns>
        public ActionResult SubMessage()
        {
            return View();
        }

        /// <summary>
        /// 接收路由
        /// </summary>
        /// <returns></returns>
        public ActionResult GetMessage()
        {
            string str = Request.Form["str"];
           ViewData["strval"]= str;
            return View();
        }

    }

    Request.Form 接收值

发送界面视图:

@{
    ViewBag.Title = "SubMessage";
}

<h2>@Html.BeginForm("GetMessage","SubInfo",FormMethod.Post)</h2>
<div>
    传值:@Html.TextBox("str")
    <input type="submit" value="发送" />
    </div>

    @Html.BeginForm(接收方法,路由,传送方式)

接收界面视图

@{
    ViewBag.Title = "GetMessage";
}

<h2>@ViewData["strval"]</h2>

=》

posted @ 2013-01-10 16:38  一抹、思乡泪  Views(239)  Comments(0Edit  收藏  举报