mvc 返回一個對象 到視圖接收
public ActionResult InfoFrame()
{
List<Users> list = new List<Users>();
Users user = new Users();
if (Session["UserID"] == null)//判斷是否沒登錄
{
return RedirectToAction("LoginIndex", "Login");
}
else
{
string sql = string.Format(@"SELECT * FROM Users WHERE UserID=‘{0}‘", Session["UserID"]);
list = DB.Database.SqlQuery<Users>(sql).ToList();
user.UserName = list[0].UserName;
}
return View(user);
}
@{
//ViewBag.Title = "InfoFrame";
}
@*@model List<MVCWEB.Models.Users>*@
@model MVCWEB.Models.Users
<html>
<head>
<link href="~/Content/css/layui.css" rel="stylesheet" />
<link href="~/Content/css/style.css" rel="stylesheet" />
<link href="~/Content/css/iconfont.css" rel="stylesheet" />
<script src="~/Scripts/jquery.js"></script>
<script src="~/Scripts/layer.js"></script>
<script src="~/Scripts/layui.js"></script>
</head>
<body>
<form class="layui-form" action="" style="margin-left:0px; margin-left:100px">
<div class="layui-form-item">
</div>
<div class="layui-form-item">
<label class="layui-form-label" style="font-size:18px;">帳號:</label>
<div class="layui-input-block">
<input type="text" name="title" value="@Model.UserName"
</div>
</div>
mvc 返回一個對象 到視圖接收