Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 325 Vote(s) - 3.66 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MVC Razor view nested foreach's model

#1
Imagine a common scenario, this is a simpler version of what I'm coming across. I actually have a couple of layers of further nesting on mine....

But this is the scenario

Theme contains List<Category>
Category contains List<Product>
Product contains List<Order>

My Controller provides a fully populated Theme, with all the Categories for that theme, the Products within this categories and the their orders.

The orders collection has a property called Quantity (amongst many others) that needs to be editable.

@model ViewModels.MyViewModels.Theme

@Html.LabelFor(Model.Theme.name)
@foreach (var category in Model.Theme)
{
@Html.LabelFor(category.name)
@foreach(var product in theme.Products)
{
@Html.LabelFor(product.name)
@foreach(var order in product.Orders)
{
@Html.TextBoxFor(order.Quantity)
@Html.TextAreaFor(order.Note)
@Html.EditorFor(order.DateRequestedDeliveryFor)
}
}
}

If I use lambda instead then then I only seem to get a reference to the top Model object, "Theme" not those within the foreach loop.


Is what I'm trying to do there even possible or have I overestimated or misunderstood what is possible?

With the above I get an error on the TextboxFor, EditorFor, etc

> CS0411: The type arguments for method
> 'System.Web.Mvc.Html.InputExtensions.TextBoxFor<TModel,TProperty>(System.Web.Mvc.HtmlHelper<TModel>,
> System.Linq.Expressions.Expression<System.Func<TModel,TProperty>>)'
> cannot be inferred from the usage. Try specifying the type arguments
> explicitly.

Thanks.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through