MVC 2 <% HTML BEGIN FORM %>与部分视图碰撞

发布于 2024-10-07 02:24:06 字数 1265 浏览 3 评论 0原文

我正在为一家公司做一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

揪着可爱 2024-10-14 02:24:06

解决了。无论如何,谢谢,我很愚蠢地添加了另一个 <% 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.

  • Derrick
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文