【发布时间】:2016-03-29 04:32:02
【问题描述】:
我在 mvc 有点新,我不知道我想念什么。当我启动登录时,在 foreach(模型中的变量项)的视图中
型号:
public class LoginModels
{
public string UserLogin { get; set; }
public string Address { get; set; }
public string Password { get; set; }
public List<string> emailSubject { get; set; }
}
控制器:
public ActionResult Login(string address, string password, LoginModels model)
{
using (Imap imap = new Imap())
{
try
{
imap.ConnectSSL("imap.gmail.com");
imap.Login(address, password);
imap.SelectInbox();
List<long> uids = imap.Search(Flag.All);
model.emailSubject = new List<string>();
foreach (long uid in uids)
{
var eml = imap.GetMessageByUID(uid);
IMail email = new MailBuilder().CreateFromEml(eml);
model.emailSubject.Add(email.Subject);
}
Session["user"] = new LoginModels() { UserLogin = address, Address = address };
return RedirectToAction("Index", "Home", model.emailSubject);
}
catch (Exception e)
{
ViewBag.exceptionMessage = e;
return View("LoginFailed");
}
}
观点:
@using TheOnlineArchivator.Models;
@model List<TheOnlineArchivator.Models.LoginModels>
@{
ViewBag.Title = "Home";
}
@{
var user = Session["user"] as LoginModels;
if (user != null)
{
<h2>You are logged on as @user.Address</h2>
<table>
@foreach (var item in Model)
{
foreach (var elem in item.emailSubject)
{
<tr>
<td>@elem</td>
</tr>
}
}
</table>
}
}
【问题讨论】:
标签: asp.net-mvc view