【问题标题】:I want to call HttpPost of Partial view on submit but it calls HttpPost of ParentView Always. Why?我想在提交时调用部分视图的 HttpPost,但它总是调用 ParentView 的 HttpPost。为什么?
【发布时间】:2013-01-15 15:19:59
【问题描述】:

我在视图(父视图)中使用局部视图

我在部分视图中有一个表单,当我点击部分视图的提交按钮时,我想调用部分视图的 [HttpPost] 方法......但它没有被调用,它只调用父级的 [HttpPost]查看...

[HttpPost]
        public ActionResult ParentView(Model model)
        {

            return View();
        }
[HttpPost]
        public ActionResult PartialView(Model model)
        {
            return View();
        }

【问题讨论】:

  • 检查表单操作是否设置为正确的操作/控制器。听起来它正在指向当前的父操作。
  • 您可能想要编辑问题的标题。目前,它的描述性不是很好。

标签: c# .net asp.net-mvc-3 web-applications partial-views


【解决方案1】:

得到解决方案...要将部分视图添加到主视图,需要使用 RenderAction() 添加

【讨论】:

  • 你能发布一些代码来演示解决方案
【解决方案2】:

两种解决方案,

首先:将控制器和动作名称显式传递给 BeginForm 方法

using (Html.BeginForm(“MyActionName”,”MyControllerName”, FormMethod.Post)) {

第二:使用jquery进行提交。为此,首先在表单上设置一个 id 并使用标准 html 输入(type=button)的点击事件调用提交。

using (Html.BeginForm(null, null, FormMethod.Post, new { id = "partialViewForm"})) {

$(‘#partialViewForm’).submit()

【讨论】:

  • 得到了解决方案...要将部分视图添加到主视图,它需要使用 RenderAction() 添加
猜你喜欢
  • 1970-01-01
  • 2016-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-03
  • 2018-09-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多