asp.net mvc 2 - Categories and Subcategories MVC2 -


At least for me there is a big problem. I have categories and unlimited subcategories. The table looks like this:

ID Parent_ID name

1 tap ride

2 1 gallapada

3 empty figure

4 2 trappers

And there is a table in which a category is responsible for. The table looks like this:

ID category_ID name

1 4 sharp

2 1 slow

3 3 high

4 2 less

Now I want to retrieve them from the database and want to show them in my MVC 2 application like this: a field set for the first class, Subcategory items should be listed in the field with the checkbox in the fields before and for one

I work with @ html.CheckBoxfor like.

Has anyone got any ideas? I have been working on this problem since last week without any results. I repeatedly tried to solve the problem but it was not working. An example would be beautiful, thanks a lot!

Thank you very much for your reply! Everything works fine! But how to make HPPoop with this model? And how is each checkbox checked or checked?

Here's my starting point:

  [HTTP post] Public ActionCent NewWorld (Newhorsmadel Collection) {Collection.Cattegories.Count (); & Lt; ------------ is always zero! Why? }    

You can create a partial view of class-class as a model Is something like this:

category.cshtml

  @model category & lt; Fieldet & gt; & Lt; Story & gt; @ Model.Name & lt; / Narrative & gt; @Wrench (option option in model) {HTML. Renderparty ("choice", item); } @oroch (Various items in model subcategories) {HTML. Renderparty ("category", item); } & Lt; / Fieldset & gt;   

Choice.cshtml @Model Stack overflow_taster.models. Options & lt; P & gt; @ Html.LabelFor (m = & gt; m selected) @html Checkbox (M => M.Selected) & lt; / P & gt;

In your main view, you will simply present a partial view based on categories:

  @forach (various items in the model) {Html.RenderPartial ( "Category", item); }   

Now you need to pass only the route categories in your views

This should give you a recurring view with categories and / or subcategories.

UPDATE

The viewhold / model can look like this:

Category.cs

  category of public category {public id ID}; Set; } Public string name {get; Set; } Public listing & lt; Category & gt; Subcategories {Receive; Set; } Public listing & lt; Choice & gt; Option {get; Set; } Public category parents {receive; Set; }}   

Choice.cs

  public class choice {Public Ent ID}; Set; } Public string name {get; Set; } Public Child Selected {get; Set; }}   

I have updated the code at the top to reflect this model

Hope this will help !

Comments