在视图中使用RenderAction时,HttpPost在MVC3中不起作用. [英] HttpPost not working in MVC3 when RenderAction is used in the view.

查看:203
本文介绍了在视图中使用RenderAction时,HttpPost在MVC3中不起作用.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在ASP.NET MVC 3.0中创建Web应用程序
在我的视图中,我需要获取一个PartialView,该PartialView使用与渲染视图所使用的模型不同的模型.因此,我使用了RenderAction()方法在渲染视图中显示PartialView.

我成功显示了PartialView,但现在出现了问题.

当我单击提交"按钮时,未调用带有[HttpPost]的控制器中的重载操作方法.请帮助我找出我要去哪里.

HomeController.cs

Hello,

I am creating a web application in ASP.NET MVC 3.0
In my View, I need to get a PartialView which uses a different model other than the model which is used by the rendering view. Hence I have used RenderAction() method to display the PartialView in the rendering View.

I was successful in displaying the PartialView but now I got a problem.

When I click on Submit button, the overload action method in the controller with [HttpPost] is not called. Please help me in finding out where am I going wrong.

HomeController.cs

public ViewResult CreateReminder()
{
     CreateReminder modelCreateReminder = new CreateReminder();
     return View();
}
[HttpPost]
public ActionResult CreateReminder(string submit, CreateReminder model)
{
     return View();
}



CreateReminder.cshtml



CreateReminder.cshtml

@model ReminderService.Models.CreateReminder


<body>
    @using (Html.BeginForm("CreateReminder", "Home", FormMethod.Post))
    {
        <p>Subject: @Html.TextBoxFor(m => m.subject)</p>
        <p>Location: @Html.TextBoxFor(m => m.location)</p>
        <p>Start Time:@{Html.RenderAction("GetCalendar", "Home");}</p>
        <p>End Time:@{Html.RenderAction("GetCalendar", "Home");}</p>
                                                                            
        <input type="submit" name="submit" value="Submit" />
        <input type="submit" name="cancel" value="Cancel" />
    }
</body>



注意:如果我使用RenderAction()删除代码行,则具有POST属性的重载操作方法将被调用.



Note: If I remove the code lines with RenderAction(), then the overload action method with POST attribute is getting invoked.

推荐答案

似乎您正在获取日期/压光机从局部控制.如果模型与之绑定,则可能是验证破坏了表单的发布.

请使用validationMessageFor html帮助程序放置消息.查看验证是否正在触发并阻止发布.

这只是一个疯狂的猜测.您需要放置部分和渲染操作的代码.因此,我可以对可能出现的问题有更多的了解.
It seems that you are getting date / calender control from the partial. If the model is bound with that it might be the validation which is breaking the posting of the form.

Please use validationMessageFor html helper to put message. See if validation is firing and blocking the posting.

It is just a wild guess. You need to put the code of partial & render action. so, i can get more idea about possible issues.


这篇关于在视图中使用RenderAction时,HttpPost在MVC3中不起作用.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆