I'm trying to (eventually) create a partial view macro that will allow visitors to select a value from a dropdown, submit a form and view the related data for the entry they selected.
I can't seem to get the post to work however. I have a method to handle the form post in my controller but I don't know how to then return to the same page with the model updated with the new data.
This is my controller code
[HttpPost]
public ActionResult HandleDropDownPostback(ConstituencyModel model)
{
var db = ApplicationContext.Current.DatabaseContext.Database;
var ccgs = db.Query<CCG>("SELECT * FROM bcg_CCGs WHERE ConstituencyCrossover = '@0'", model.ConstituencySelected);
model.Ccgs = ccgs;
return PartialView("ConstituencyDropDown", model);
}
But when the form is submitted all I get is a plain page with the form on it.
Firstly i would not use umbracoBeginForm or RedirectToPage
I would use standard Html and Ajax posts
It sounds like you want to use AJAX to re-render a portion of the page on post back? Is this correct.
Are you going to your controller from a view or partial view? If you go from a view you need to go back to a view, if you go from a partial you need to go back to a partial, thus you need AJAX to rerender that partial.
I think this is where your problem is. You are posting back a partial view result using a HTML POST which is re-rendeing the page with just the partial and not the whole page with everything.
It was my intention to have an AJAX post that renders a section on the page. But as I didn't know how to call the controller from the javascript I thought just making a simple for that posts back to the same page would be easier. Don't think it was though :p
What I wanted was the MVC equivelant of an auto postback drop down list where upon selecting an item in the drop down the details for that item are shown on the same page. I've not done a lot of MVC though and I had a (very) tight deadline so I couldn't take my time and learn how to do it properly.
If I'm honest I don't really understand what you said. It makes common sense which is a start I suppose ;)
Controller postback current page
I'm trying to (eventually) create a partial view macro that will allow visitors to select a value from a dropdown, submit a form and view the related data for the entry they selected.
I can't seem to get the post to work however. I have a method to handle the form post in my controller but I don't know how to then return to the same page with the model updated with the new data.
This is my controller code
But when the form is submitted all I get is a plain page with the form on it.
Can anyone help.
Managed to hack something together. Although I'd like to know the correct way to do something like this.
This is my controller
And my partial view
Firstly i would not use umbracoBeginForm or RedirectToPage
I would use standard Html and Ajax posts
It sounds like you want to use AJAX to re-render a portion of the page on post back? Is this correct.
Are you going to your controller from a view or partial view? If you go from a view you need to go back to a view, if you go from a partial you need to go back to a partial, thus you need AJAX to rerender that partial.
I think this is where your problem is. You are posting back a partial view result using a HTML POST which is re-rendeing the page with just the partial and not the whole page with everything.
Does that make sense?
Charlie :)
It was my intention to have an AJAX post that renders a section on the page. But as I didn't know how to call the controller from the javascript I thought just making a simple for that posts back to the same page would be easier. Don't think it was though :p
What I wanted was the MVC equivelant of an auto postback drop down list where upon selecting an item in the drop down the details for that item are shown on the same page. I've not done a lot of MVC though and I had a (very) tight deadline so I couldn't take my time and learn how to do it properly.
If I'm honest I don't really understand what you said. It makes common sense which is a start I suppose ;)
Dear Suzyb,
i m struggling to search database data using postback..i m using same technique like you
TempData["ccgs"] = res;
but tempdata ccgs is null when i got it in view
plz help me in this..urgent!
The only thing I can suggest is to make sure your controller inherits from SurfaceController.
Not sure why TempDate would be null as I don't really understand how my code works :p
hahaha....suzyb...are you not working on this project now...
you leave umbarco...
i have completed that using session variable and get session data in view...
any issue with this?
Thanks for answering ...forget to mention before...
is working on a reply...