日期:2014-05-17  浏览次数:20405 次

怎么把viewData["userName"]传到home文件夹的index页面
我的AccountController里面想把viewdata["userName"]传到home的index页面中,要怎么传啊??


  [HttpPost]
        public ActionResult Login(FormCollection form)
        {
            if (CanLogin(form["userName"], form["password"]) == true)
            {
                ViewData["userName"] = form["userName"];
                return RedirectToAction("Index", "Home" ,ViewData["userName"]);
            }
            return View();
        }



页面是这样子的:


<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    主页
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        <%: ViewData["Message"] %></h2>
    <p>
        欢迎:<%=ViewData["userName"]%></p>
     
</asp:Content>




怎么欢迎那里不会显示userName????

------解决方案--------------------
public ActionResult Login(FormCollection form)
{
    ...
    return RedirectToAction("Index", "Home" , new { uname = ViewData["userName"] });
    ...
}

HomeController的Index
ActionResult Index(string umane)
{
    你的Model m = ...;
    m.uname = uname;
    return View(m);
}

页面
欢迎:<%=@model.umane%></p>