How to display content from a controller action in partial view
I have created a controller action method like this
public class RegistrationFormSurfaceController : SurfaceController
{
[HttpGet]
public ActionResult MemberProfile(RegistrationFormViewModel model)
{
//Get registration data from Database
// fill "model" with the data
return View(model);
}
}
this doesn't throws any error neither shows the data. I know this is not the right approach make this work. Can anyone please point out what all I am missing? So that I can send data from a controller and display it in a partial view.
public class RegistrationFormSurfaceController : SurfaceController
{
public ActionResult MemberProfile()
{
var model = new RegistrationFormViewModel();
//Get registration data from Database fill "model" with the data
model.Address = "This is a test";
return View("USNAdvancedPageComponents/TDN_MemberProfile", model);
}
}
as Dennis stated the Problem was that your controller method has a parameter which is not send with the action method. Make the changes he suggest and it should work.
The view 'USNAdvancedPageComponents/TDN_MemberProfile' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/RegistrationFormSurface/USNAdvancedPageComponents/TDN_MemberProfile.aspx
~/Views/RegistrationFormSurface/USNAdvancedPageComponents/TDN_MemberProfile.ascx
~/Views/Shared/USNAdvancedPageComponents/TDN_MemberProfile.aspx
~/Views/Shared/USNAdvancedPageComponents/TDN_MemberProfile.ascx
~/Views/RegistrationFormSurface/USNAdvancedPageComponents/TDN_MemberProfile.cshtml
~/Views/RegistrationFormSurface/USNAdvancedPageComponents/TDN_MemberProfile.vbhtml
~/Views/Shared/USNAdvancedPageComponents/TDN_MemberProfile.cshtml
~/Views/Shared/USNAdvancedPageComponents/TDN_MemberProfile.vbhtml
And to make things clear this is the path to my partial file in Root folder
How to display content from a controller action in partial view
I have created a controller action method like this
and my partial view is like this
And on my template I am calling this view like this
this doesn't throws any error neither shows the data. I know this is not the right approach make this work. Can anyone please point out what all I am missing? So that I can send data from a controller and display it in a partial view.
Hi Athul,
the Html.Partial helper just shows the partial view with the model your passing. In your case thats an empty model.
For going to the controller and fetch your data from the db you have to use
this calls the controller and returns your partial view with your data.
Regards David
Now it throws an error
Hi athul.
Try the following:
Your controller:
Your partial:
And your template:
Remember that you need to build your solution (if you haveĀ“nt got all your files in App_Code) in order for Umbraco to pick up your routes.
Hope this helps!
Hi athul,
as Dennis stated the Problem was that your controller method has a parameter which is not send with the action method. Make the changes he suggest and it should work.
Regards David
Hi All, Now it throws an error
And to make things clear this is the path to my partial file in Root folder
My controller path
Hi athul,
as Dennis mentioned mvc can't find the view as the path is not correct. But instead of adding the whole path I would change the return to
and then move the view TDN_MemberProfile.cshtml directly to the partial folder. In my opinion that would be the correct way where to store the view.
Regards David
Unless you want to have all your partial components in one place, then you should keep it where it is and in your controller return:
return View("/Views/Partials/USNAdvancedPageComponents/TDN_MemberProfile.cshtml", model);
is working on a reply...