Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
C#
public ViewResult CreateReminder()
{
     CreateReminder modelCreateReminder = new CreateReminder();
     return View();
}
[HttpPost]
public ActionResult CreateReminder(string submit, CreateReminder model)
{
     return View();
}


CreateReminder.cshtml

C#
@model ReminderService.Models.CreateReminder

HTML
<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>


Note: If I remove the code lines with RenderAction(), then the overload action method with POST attribute is getting invoked.
Posted
Comments
Sampath Lokuge 4-Dec-13 5:25am    
Is that giving any run time error or what happen ?
bpc1989 4-Dec-13 6:08am    
No Runtime error.... Just nothing happens when I click on Submit.
Sampath Lokuge 4-Dec-13 6:12am    
Can you put code snippets for those action methods also (partial)?
Sampath Lokuge 4-Dec-13 6:14am    
And also check is there any errors when you press the save (using chrome dev tools) ?

1 solution

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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900