Your select element's closing tag seems to be a script closing tag - Yeah that was a mistake when writing it in here lol
Only use @ when you're outputting something to the markup, example: no need to use this in your foreach() - Point noted thanks :-)
none of the last two work, all i want it to do is take a value from the page that it is on and pass it to the varible and use it in the courseListFaculty = whatever that varible is so that the correct dropdown is displayed :-(
Oh I totally missed you putting Passfaculty in a variable, sorry!
My guess of something that may work or perhaps give you a better error message:
@{
//You may wish to move this @block to the top of the page in time just to keep the markup more clear (eventually into Controller)
//Changing a few things to make it strongly typed for better debugging
var passfaculty = CurrentPage.GetPropertyValue<String>("facultyName"); //make sure the current page has a property with alias "facultyName"
var home = CurrentPage.AncestorOrSelf(1);
//You may wish to make this search based upon Document Type in time - also check the name of the page below home is exactly "Courselist"
var courseListPage = home.Single(x => x.Name.Equals("Courselist"));
//For the next line, make sure that the Children under the courseListPage have a property with the property alias of "courseListFaculty"
var coursePages = courseListPage.Children.Select(x => x.GetPropertyValue<String>("courseListFaculty").Equals(passFaculty));
}
<select class="form-control" id="CourseCodeSelect">
<option selected="selected" value="0">Choose a Course</option>
@foreach (var coursePage in coursePages){
var schoolcode = coursePage.GetPropertyValue<String>("courseListSchoolCode"); //is this a string or int? I'm guessing String! - also make sure the course page has a property with alias "courseListSchoolCode"
<option value="@schoolcode">@coursePage.Name</option>
}
</select>
I may have made a few typos as all is done in this markdown editor, but give that a go and see if a better error message pops up! :)
@{
var passfaculty = CurrentPage.GetPropertyValue<String>("facultyName");
//make sure the current page has a property with alias "facultyName" - It does
var home = CurrentPage.AncestorOrSelf(1);
//You may wish to make this search based upon Document Type
//in time - also check the name of the page below home is exactly "Courselist"
var courseListPage = home.Single(x => x.Name.Equals("Courselist"));
//For the next line, make sure that the Children under
//the courseListPage have a property with the property alias of "courseListFaculty" - it does
var coursePages = courseListPage.Children.Select(x => x.GetPropertyValue<String>("courseListFaculty").Equals(passFaculty));
}
<select class="form-control" id="CourseCodeSelect">
<option selected="selected" value="0">Choose a Course</option>
@foreach (var coursePage in coursePages){
var schoolcode = coursePage.GetPropertyValue<String>("courseListSchoolCode");
//is this a string or int? its a string :-)
//Im guessing String! - also make sure the course page has a property with
//alias "courseListSchoolCode"
<option value="@schoolcode">@coursePage.Name</option>
}
</select>
I have added a few comments but still getting an error
Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
below is where i am trying to pull them from its like a database table type of thing in the backend where the users can enter info into then by the faculty the correct list from the full list is displayed throughout the site :-)
Yeah that doesnt seem to work either :-( the facultyName is on the courselist repository and and also on the faculty pages of the site so what i am trying to do is say for instance the faculty "A Level" on the A Level page and that drop down would only show the A Level courses from the CourseList Repository it does work as shown below but each time a new faculy gets added i need to go add a new one for the marketing team :-(
@if (faculty == "A Level"){
foreach (var pageCourse in @Model.Content.AncestorOrSelf(1).Children.Where(x => x.Name == "Courselist")){
foreach (var subpageCourse in pageCourse.Children.Where("courseListFaculty == \"A Level\"")){
var content = Umbraco.TypedContent(@subpageCourse.Id);
var schoolcode = content.GetPropertyValue("courseListSchoolCode");
<option value="@schoolcode">@subpageCourse.Name</option>
}
}
}
else if (faculty == "Accountancy"){
foreach (var pageCourse in @Model.Content.AncestorOrSelf(1).Children.Where(x => x.Name == "Courselist")){
foreach (var subpageCourse in pageCourse.Children.Where("courseListFaculty == \"Accountancy\"")){
var content = Umbraco.TypedContent(@subpageCourse.Id);
var schoolcode = content.GetPropertyValue("courseListSchoolCode");
<option value="@schoolcode">@subpageCourse.Name</option>
}
}
}
else if (faculty == "Marketing"){
foreach (var pageCourse in @Model.Content.AncestorOrSelf(1).Children.Where(x => x.Name == "Courselist")){
foreach (var subpageCourse in pageCourse.Children.Where("courseListFaculty == \"Marketing\"")){
var content = Umbraco.TypedContent(@subpageCourse.Id);
var schoolcode = content.GetPropertyValue("courseListSchoolCode");
<option value="@schoolcode">@subpageCourse.Name</option>
}
}
}
else if (faculty == "Leadership and Management"){
foreach (var pageCourse in @Model.Content.AncestorOrSelf(1).Children.Where(x => x.Name == "Courselist")){
foreach (var subpageCourse in pageCourse.Children.Where("courseListFaculty == \"Leadership and Management\"")){
var content = Umbraco.TypedContent(@subpageCourse.Id);
var schoolcode = content.GetPropertyValue("courseListSchoolCode");
<option value="@schoolcode">@subpageCourse.Name</option>
}
}
}
else if (faculty == "Procurement and Supply"){
foreach (var pageCourse in @Model.Content.AncestorOrSelf(1).Children.Where(x => x.Name == "Courselist")){
foreach (var subpageCourse in pageCourse.Children.Where("courseListFaculty == \"Procurement and Supply\"")){
var content = Umbraco.TypedContent(@subpageCourse.Id);
var schoolcode = content.GetPropertyValue("courseListSchoolCode");
<option value="@schoolcode">@subpageCourse.Name</option>
}
}
}
else if (faculty == "GCSE and IGCSE"){
foreach (var pageCourse in @Model.Content.AncestorOrSelf(1).Children.Where(x => x.Name == "Courselist")){
foreach (var subpageCourse in pageCourse.Children.Where("courseListFaculty == \"GCSE and IGCSE\"")){
var content = Umbraco.TypedContent(@subpageCourse.Id);
var schoolcode = content.GetPropertyValue("courseListSchoolCode");
<option value="@schoolcode">@subpageCourse.Name</option>
}
}
}
else if (faculty == "Learning and Development"){
foreach (var pageCourse in @Model.Content.AncestorOrSelf(1).Children.Where(x => x.Name == "Courselist")){
foreach (var subpageCourse in pageCourse.Children.Where("courseListFaculty == \"Learning and Development\"")){
var content = Umbraco.TypedContent(@subpageCourse.Id);
var schoolcode = content.GetPropertyValue("courseListSchoolCode");
<option value="@schoolcode">@subpageCourse.Name</option>
}
}
}
else if (faculty == "Human Resources"){
foreach (var pageCourse in @Model.Content.AncestorOrSelf(1).Children.Where(x => x.Name == "Courselist")){
foreach (var subpageCourse in pageCourse.Children.Where("courseListFaculty == \"Human Resources\"")){
var content = Umbraco.TypedContent(@subpageCourse.Id);
var schoolcode = content.GetPropertyValue("courseListSchoolCode");
<option value="@schoolcode">@subpageCourse.Name</option>
}
}
}
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Umbraco.Web.Models.PublishedContentWithKeyBase' does not contain a definition for 'GetPropertyValue'
that is the error i get is i add AsDynamic so looks like we are getting closer :-)
Where am i going wrong
Can anybody tell me where i am going wrong here? why wont it let me pass the string?
<select class="form-control" id="CourseCodeSelect"> <option selected="selected" value="0">Choose a Course</option> @{ string Passfaculty = CurrentPage.facultyName; foreach (var pageCourse in @Model.Content.AncestorOrSelf(1).Children.Where(x => x.Name == "Courselist")){ foreach (var subpageCourse in Model.Children.Where("courseListFaculty = @0", "@Passfaculty")){ var content = Umbraco.TypedContent(@subpageCourse.Id); var schoolcode = content.GetPropertyValue("courseListSchoolCode"); <option value="@schoolcode">@subpageCourse.Name</option> } } } </select>
I see a couple of things that look a bit off:
Your Model.Children.Where() seems a bit odd, perhaps you're looking to do something like:
Not sure if Passfaculty is a variable or not!
You're foraching pageCourse but not using the variable, perhaps you mean something like:
A few things to try out :)
Your select element's closing tag seems to be a script closing tag - Yeah that was a mistake when writing it in here lol
Only use @ when you're outputting something to the markup, example: no need to use this in your foreach() - Point noted thanks :-)
none of the last two work, all i want it to do is take a value from the page that it is on and pass it to the varible and use it in the courseListFaculty = whatever that varible is so that the correct dropdown is displayed :-(
Oh I totally missed you putting Passfaculty in a variable, sorry!
My guess of something that may work or perhaps give you a better error message:
I may have made a few typos as all is done in this markdown editor, but give that a go and see if a better error message pops up! :)
I have added a few comments but still getting an error
Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
below is where i am trying to pull them from its like a database table type of thing in the backend where the users can enter info into then by the faculty the correct list from the full list is displayed throughout the site :-)
It seems like I assumed wrong about "courseListFaculty" being a String in the line:
Just a random guess here since I'm not 100% inside your solution, but maybe:
instead would do? Or perhaps something similar? This isn't very pretty, but perhaps it would work untill refactored?
Yeah that doesnt seem to work either :-( the facultyName is on the courselist repository and and also on the faculty pages of the site so what i am trying to do is say for instance the faculty "A Level" on the A Level page and that drop down would only show the A Level courses from the CourseList Repository it does work as shown below but each time a new faculy gets added i need to go add a new one for the marketing team :-(
Thanks
Aha, I'm not quite sure about these data types, but perhaps in your first post, you could just change the:
to
?
Yeah thats what i thought at first but got this error
"0" is not valid at the start of a code block. Only identifiers, keywords, comments, "(" and "{" are valid.
the thing that i am trying to achieve should be so easy it is bugging me how i cant solve it lol
I now have a new error :-(
What if you instead do:
in the line of the error?
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Umbraco.Web.Models.PublishedContentWithKeyBase' does not contain a definition for 'GetPropertyValue'
that is the error i get is i add AsDynamic so looks like we are getting closer :-)
then
maybe?
Dynamic types, what a mess... :)
Yeah thanks, i just had a total code mind block today that is it working perfect :-)
No worries! Just be sure to refactor it at some point, future you will thank you endlessly! :)
is working on a reply...