Link to home
Start Free TrialLog in
Avatar of Johny Bravo
Johny Bravo

asked on

Asp.Net MVC dropdown

Hello Experts,

I am learning MVC so please help me.

I am using Entity Framework for CRUD operation.

When I generate Controller/ View for Products, it creates Index/ Edit/ Details/ Delete view.

What I need is, in Create View, it creates only one dropdown for "SubCategory", instead I want to have "Category" Dropdown
and after its selection "SubCategory" dropdown.

Your help is appreciated. Thanks
dbpng.png
SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Johny Bravo
Johny Bravo

ASKER

View / Model / Controller are attached.

Please check
Create.txt
ProductsController.txt
Product.txt
Ok now what I've done,

      <div class="editor-label">
            @Html.LabelFor(model => model.CategoryId, "Category")
        </div>
        <div class="editor-field">
            @Html.DropDownList("CategoryId", String.Empty)
            @Html.ValidationMessageFor(model => model.CategoryId)

        </div>

and in controller,
   ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName");

so it creates a Category dropdown, but I need subcategory dropdown to be filled based on the selection of Category.

>>Moving from Asp.Net to MVC is a bit difficult :)
>>As in Asp.Net, we could have AutoPostBack="true" and fill the Subcategory ddl.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial