【发布时间】:2011-09-22 23:15:32
【问题描述】:
我正在尝试实现一个包含主题的简单博客
models/Topic.cs
public class Topic
{
public int ID {get; set;}
[StringLength(50)]
[RequiredAttribute(ErrorMessage = "*")]
public string Title {get; set;}
[StringLength(1024)]
[RequiredAttribute(ErrorMessage = "*")]
public string Body { get; set; }
public int CommentsCount { get; set; }
public DateTime TimeLastUpdated { get; set; }
public int AuthorID { get; set; }
public virtual List<Comment> commentsList { get; set; }
}
主页看起来像一个主题列表。
Controllers/HomeController.cs
public class HomeController : Controller
private ContentStorage db = new ContentStorage();
public ViewResult Index()
{
// Topics = DbSet<Topic> Topics { get; set; }
return View(db.Topics.ToList());
}
[HttpPost]
public void LogIn(string login, string password)
{
int i;
i = 10;
}
}
主页的视图很简单。
观看次数/首页/索引
@model IEnumerable<MvcSimpleBlog.Models.Topic>
...
<table width="95%" height="86" border="0">
<tr>
<td width="45%" valign = "bottom" >Login:</td>
<td width="45%" valign = "bottom" >Password:</td>
<td width="10%"></td>
</tr>
<tr>
<td width="45%"><p> <input type="text" name="login" /> </p></td>
<td width="45%"><p><input type="password" name="password" /></p></td>
<td width="10%" align = "left">
@using (Html.BeginForm("LogIn", "Home"))
{
<input type = "submit" value = "Enter" />
}
</td>
</tr>
<tr>
<td width="45%" valign = "top" >@Html.ActionLink("Register", "Register", "Account")</td>
</tr>
</table>
如何将视图中编辑框中的值传递给 HomeController 方法? “LogIn”方法应该从视图接收数据,调用“Account”控制器,将用户的登录名和密码传递给它。 “帐户”控制器应验证此用户并将浏览器重定向到带有主题的主页。
但我无法访问视图中的登录名和密码编辑框...而且我真的不知道该怎么办,我的模型是否正确
【问题讨论】:
标签: asp.net-mvc-3 razor