i am new in mvc and just reading a article from this link http://weblogs.asp.net/scottgu/ef-code-first-and-data-scaffolding-with-the-asp-net-mvc-3-tools-update
view the below image there is two model class one is product and one is category and category class has one property called Products which return ICollection
and when generate UI with scaffolding pointing to product model class then UI generate with product details and a dropdown appear for category.
i just do not understand how scaffolding incorporate a drodown for category when generate a UI page for product. product has no link for category but how category related drodown comes in product page. just help me to understand it. thanks
here are few screen shot
i just like to know when we generate product view page using scaffolding then we point our product model class and product model class has no property for category then why and how category related drop down appear in product view page. if u know the reason then share the concept in detail. thanks
Related
I apologize if this is a newb question. I'm more experienced with Windows forms and just getting started with MVC. I have a class called PackagedProduct which consists of a Package and a Product that are selected via drop down list and represented by their own models.
PackagedProduct
Sometimes though, the Product may not exist yet so I have an ActionLink that directs to the Create action of Product.
#Html.ActionLink("Create New Product", "Create", "Products");
Product
How can I allow the user to create the new Product, but when the create button is pressed to return to the PackagedProduct view where it originated with the existing data still populated(in this case UPCCode and Package)? The PackagedProduct won't have been created yet because it is missing required data until the correct Product is created so I can't just pass back the PackagedProductID. Thoughts?
I use MVC with View Models (I create separate View Model for each View).
I have 2 objects; Product and Category; Product can have a category.
I have separate view models (productCreateVM, CategoryCreateVM)
I can create product or category;and user can choose one of current categories while creating a new product, no problem.
What I need to do is that ; users can choose one of current categories or create a new category than choose it, while creating a new product.
If I add CategoryCreateVM in ProductCreateVM, then CategoryCreateVM's mandatory fields need to be filled in, in order the model state to be valid.
but if user already found a category for their product and didnt create a new one; I can not fill all the mandatory fields of CategoryCreateVM.
On the other hand; if user is creating a new category from product create view; then all the validations should be applied (category name lenght etc).
Any suggestions how to approach to this?
If you want to use more complex validations see if http://foolproof.codeplex.com/ will be sufficient.
It it should provide you with the conditional validation you need
You should consider rendering the Create Category View as a partial view within the Create Product View.
Its visibility can be toggled by e.g. the selection of Create Category within a Category drop-down menu.
For example:
#Html.Partial("Category/Create")
I am working on my first MVC 4 application. We are using Model first approach for this application. I am working on the add employee module which has multistep wizard.
Employee class looks like below, it has couple of navigation properties for other tables,
Employee
{
Employee Properties;
.
.
ICollection <ASSET>;
ICollection <TEAMS>;
}
I am using a viewmodel having an object of employee entity and other Select list objects for the dropdown lists required during add process.
public class EmployeeViewModel
{
Employee NewEmp;
.
.
List<Country> Dropdown1;
List<City> DropDown2;
.
.
}
I have created a strongly typed view to pass this viewmodel in add screen.
Add wizard is divided into 8 steps and each step is rendered through partial view. Everything works fine for the properties of Employee entity. But I have steps where,
User can select from assets from dropdown list and tag them to employee currently being added.
User can tag employee to the team, select employee role,etc.
I want to re-use these partial views in edit mode also, so I believe the navigation properties will have list of valid objects in case of edit mode. The idea is to add/edit all the information in viewmodel and save it to database on finish button.
I want to understand how can I create and add the objects for navigation properties in current viewmodel. Also how can I re-use these 2 steps in edit mode ? Can I create new team objects at client side and add it into a employee object collection list? Is there any other way (like using Ajax) to implement this functionality? Please help me because I am really stuck with this from long time.
I am a newbie to nopcommerce mvc framework.I have a side category navigation which shows all the categories and subcategories in almost all pages where i need, except in single product page.In the single product page,Side menu displays only the main categories whereas i wanted to display main category and the subcategory.Can anyone suggest me the solution?
make sure your product details view inherit from the _ColumnsTwo.cshtml
I am trying to understand how associated entities are updated when using custom modelbinders.
If you have a Product entity with a relationship to a Category entity and you are displaying a list of category choice for a product in a dropdown on a form.
The the user assigns a new category and that change needs to be persisted with the Product. How is the binding implemented to assign the updated category? The properties f the Product are easy enough, but how do you set the Product.Category = category?
Hope that is clear :-)
Sounds like your custom model binding is there, you're just trying to setup up your relationship between your Product and Category.
To do this you would do something like this:
product.CategoryReference.EntityKey =
new EntityKey("Context.Category", "ID", categoryID);
That will simply update the foreign key relationship in your entity.