将模型从强类型视图传递回控制器操作 - mvc2 VB.net
这就是我所拥有的。我有一个 MVC 应用程序,其中所有数据都通过数据库中的 VisitDate 表绑定在一起。主页是 VisitDate 类型的强类型视图,它所做的只是提取一些简单的数据。现在,这就是我遇到问题的地方。我需要一个链接,将视图中的当前模型传递回单独的控制器操作,以便我可以使用不同的数据渲染不同的页面。
这是我的两个控制器操作。我将从 News.aspx 转到 FrontPage.aspx,并希望能够通过 SchoolVisit。
Function News(ByVal SchoolVisit As SchoolVisitDate) As ActionResult
Dim db As New NewsData.NewsDB
Dim repos As New NewsRepository
Dim _classId As Integer
_classId = (From a In db.SchoolClasses Where a.VisitDateID = SchoolVisit.VisitDateID Select a.ClassID).Single()
ViewData("VisitDate") = FormatDateTime(SchoolVisit.VisitDate, vbShortDate)
ViewData("Staff") = repos.GetStaff(_classId)
ViewData("StockArticles") = From a In db.StockArticles Select a
ViewData("Articles") = repos.GetArticles(_classId)
Return View()
End Function
Function FrontPage(ByVal SchoolVisit As SchoolVisitDate) As ActionResult
Dim repos As New NewsRepository
Dim _VisitDateID As Integer
_VisitDateID = SchoolVisit.VisitDateID
ViewData("Editorial") = repos.GetEditorial(_VisitDateID)
Return View()
End Function
Here's what I have. I have an MVC application where all the data is tied together by VisitDate table in my database. The home page is a strongly typed view of type VisitDate, all it does is pull up some simple data. Now, here's where I'm having a problemo. I need a link that passes the current model in the view back to a seperate controller action so I can render a different page with different data.
Here are my two controller actions. I'm going from News.aspx to FrontPage.aspx and hopefully passing SchoolVisit.
Function News(ByVal SchoolVisit As SchoolVisitDate) As ActionResult
Dim db As New NewsData.NewsDB
Dim repos As New NewsRepository
Dim _classId As Integer
_classId = (From a In db.SchoolClasses Where a.VisitDateID = SchoolVisit.VisitDateID Select a.ClassID).Single()
ViewData("VisitDate") = FormatDateTime(SchoolVisit.VisitDate, vbShortDate)
ViewData("Staff") = repos.GetStaff(_classId)
ViewData("StockArticles") = From a In db.StockArticles Select a
ViewData("Articles") = repos.GetArticles(_classId)
Return View()
End Function
Function FrontPage(ByVal SchoolVisit As SchoolVisitDate) As ActionResult
Dim repos As New NewsRepository
Dim _VisitDateID As Integer
_VisitDateID = SchoolVisit.VisitDateID
ViewData("Editorial") = repos.GetEditorial(_VisitDateID)
Return View()
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Html.ActionLink 可以提供帮助
Html.ActionLink can be of help
您需要执行以下操作:
Here's what you have to do: