MVC 2 <% HTML BEGIN FORM %>与部分视图碰撞
我正在为一家公司做一个 MVC 2 vb 项目,以下代码用于通过 model.edmx 检索数据库表。我有多个选项卡,我已经实现了单独的部分视图来包含数据。 查看页面
<% Using Html.BeginForm("BkgEntry", "BookingController")%>
<input button type="submit" />
.
.
.
<div> <% Html.RenderPartial("~/Views/Booking/pax.ascx", ViewData("pax"))%></div>
<div> <% Html.RenderPartial("~/Views/Booking/itinerary.ascx", ViewData("itinerary"))%></div>
<% End Using %>
控制器页面
<HttpPost()>
Function BkgEntry(ByVal collection As FormCollection, ByVal bill As Billing, ByVal pax As Pax, ByVal Itinerary As Itinerary, ByVal id As Integer) As ActionResult
.
.
.
_db.ApplyCurrentValues(billing.EntityKey.EntitySetName, bill)
_db.ApplyCurrentValues(pa.EntityKey.EntitySetName, pax)
_db.ApplyCurrentValues(itin.EntityKey.EntitySetName, Itinerary)
_db.SaveChanges()
Return RedirectToAction("BkgEntry")
End Function
所以这就是问题,当我单击“提交”按钮时,它会弹出一个错误,引用“_db.ApplyCurrentValues(itin.EntityKey.EntitySetName, Itinerary)” '“行程”为空,无法更新。
这是因为“Itinerary”未传递到 BkgEntry post 函数中。不像帕克斯和比尔能够做到。我尝试了几种方法,我想知道是否是因为多个部分表单与 <%Html Begin form%> 冲突导致视图错误,如果是这样,我该如何解决它?
I am doing a MVC 2 vb project for a company, and the following codes are used to retrieve database tables thru model.edmx. I have mutiple tabs which I've implemented separate partial views to contain the data.
View page
<% Using Html.BeginForm("BkgEntry", "BookingController")%>
<input button type="submit" />
.
.
.
<div> <% Html.RenderPartial("~/Views/Booking/pax.ascx", ViewData("pax"))%></div>
<div> <% Html.RenderPartial("~/Views/Booking/itinerary.ascx", ViewData("itinerary"))%></div>
<% End Using %>
Controller page
<HttpPost()>
Function BkgEntry(ByVal collection As FormCollection, ByVal bill As Billing, ByVal pax As Pax, ByVal Itinerary As Itinerary, ByVal id As Integer) As ActionResult
.
.
.
_db.ApplyCurrentValues(billing.EntityKey.EntitySetName, bill)
_db.ApplyCurrentValues(pa.EntityKey.EntitySetName, pax)
_db.ApplyCurrentValues(itin.EntityKey.EntitySetName, Itinerary)
_db.SaveChanges()
Return RedirectToAction("BkgEntry")
End Function
So here's the problem, when I click on "submit" button, it pops out an error refering to '_db.ApplyCurrentValues(itin.EntityKey.EntitySetName, Itinerary)
' that "itinerary" is null there it cannot be updated.
This is because "Itinerary" wasnt passed into the BkgEntry post function. Unlike Pax and Bill was able to. I have tried several methods and I derived at wondering if it is because of mutiple partial forms coliding with <%Html Begin form%>that cause the error at the view, if so, how can I solve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了。无论如何,谢谢,我很愚蠢地添加了另一个 <% HtmlBegin Form%> 。和<%结束使用%>在单独的部分视图中,我猜 <% End using %> 是这样的:在第一个部分中关闭了我的整个 <% HtmlBeign Form %>开始时的操作。
Solved. thanks anyway, it was just silly of me to include another <% HtmlBegin Form%> and <% End Using %> in the separate partial views as well, i guess the <% End Using %> in the first partial shuts down my whole <% HtmlBeign Form %> operation at the start.