Most of it works, but I am a bit confused. I retrieve data from MediaService to list audio files in different subfolders. The data is presented OK. Then I want to allow the user to swap to another folder by changing a DropDownlist. Then everything goes wrong.
1) First I am a bit confused on how to trigger on Dropdown change. Should I use jQuery or can Razor helpers help me?
2) Right now I use a button to trigger new selection. It kind of works. The new data is rendered all right, but all of my layout disappears! The master page with all menus and styling is gone.
I guess it all boils down to how partial views work together with templates and document types when posting data in the form. It seems that I lost track somewhere ... :)
Any help very much appreciated!
Controller
public class AudioListSurfaceController : SurfaceController
{
public ActionResult Index()
{
var audioListModel = new AudioListModel();
var sermonFolder = GetSermonFolder();
if (sermonFolder != null)
{
audioListModel.YearFolderNames = sermonFolder.Children().Select(f => f.Name).ToList();
audioListModel.YearFolderName = audioListModel.YearFolderNames.OrderByDescending(x => x).FirstOrDefault();
}
return Search(audioListModel);
}
[HttpPost]
public ActionResult Search(AudioListModel audioListModel)
{
var sermonFolder = GetSermonFolder();
if (sermonFolder != null)
{
audioListModel.YearFolderNames = sermonFolder.Children().Select(f => f.Name).ToList();
var yearFolder = sermonFolder.Children().SingleOrDefault(f => f.Name == audioListModel.YearFolderName);
if (yearFolder != null)
{
foreach (var mediaItem in yearFolder.Children())
{
audioListModel.AudioModels.Add(new AudioModel
{
Title = mediaItem.Name,
Author = mediaItem.GetValue<string>("author"),
Date = mediaItem.GetValue<DateTime>("date"),
Location = mediaItem.GetValue<string>("location"),
Size = mediaItem.GetValue<string>("size"),
SizeBytes = mediaItem.GetValue<int>("sizeBytes"),
Duration = TimeSpan.FromSeconds(mediaItem.GetValue<int>("durationSeconds")),
Path = mediaItem.GetValue<string>("umbracoFile"),
});
}
}
}
return PartialView("AudioListForm", audioListModel);
}
private IMedia GetSermonFolder()
{
var sermonFolder = Services.MediaService.GetRootMedia().FirstOrDefault(folder => folder.ContentType.Alias == "audioFolder" && folder.Name == "Predikningar");
return sermonFolder;
}
}
Not sure if the exact technical reasons, but when you have a Surface Controller with a Post Action, you can't return the partial view to the page (unless it's a ChildAction and not a Post). So returning CurrentUmbracoPage() should resolve the issue.
Edit: I should note that this will fix the issue of your page not having any formatting. I think you will then have to reconsider how you get your data back to the page.
I want to create a webpage in Umbraco where I can make same criteria selections in controls (like dropdownlist). When submitted these criteria should produce a list with custom data returned back to the same page. When criteria is modified again the result is rerendered.
Hi Jakob, know this old post... have you sorted your problem I am facing similar problems .
if i call renturn PartialView () then it render only view with out master page layout. If I call return to currentumbracopagethen i get error public method not found in controller as macro action name is different.
Partial view form causes all layout to disappear
I listened to all Umbraco videos and I am now trying to apply my knowledge. This video talks of partial views as a means to present custom data. http://umbraco.tv/videos/developer/fundamentals/surface-controllers/handling-posts/
Most of it works, but I am a bit confused. I retrieve data from MediaService to list audio files in different subfolders. The data is presented OK. Then I want to allow the user to swap to another folder by changing a DropDownlist. Then everything goes wrong.
1) First I am a bit confused on how to trigger on Dropdown change. Should I use jQuery or can Razor helpers help me?
2) Right now I use a button to trigger new selection. It kind of works. The new data is rendered all right, but all of my layout disappears! The master page with all menus and styling is gone.
I guess it all boils down to how partial views work together with templates and document types when posting data in the form. It seems that I lost track somewhere ... :)
Any help very much appreciated!
Controller
Partial View
Hosting Template
Hi Jakob,
Replacing the line:
with the following:
Not sure if the exact technical reasons, but when you have a Surface Controller with a Post Action, you can't return the partial view to the page (unless it's a ChildAction and not a Post). So returning CurrentUmbracoPage() should resolve the issue.
Edit: I should note that this will fix the issue of your page not having any formatting. I think you will then have to reconsider how you get your data back to the page.
Regards, Phill
So you mean I can have my layout back as long as I skip all data I retrieved ... ? That sounds like a strange answer.
Let me rephrase my question:
I want to create a webpage in Umbraco where I can make same criteria selections in controls (like dropdownlist). When submitted these criteria should produce a list with custom data returned back to the same page. When criteria is modified again the result is rerendered.
Is this not possible????
Hi Jakob, know this old post... have you sorted your problem I am facing similar problems .
if i call renturn PartialView () then it render only view with out master page layout. If I call return to currentumbracopagethen i get error public method not found in controller as macro action name is different.
is working on a reply...