asp.net mvc - ASP MVC - How use two models in one single view -


I have a web page that has two functions 1) Add new products 2) Display existing products in a table (See image below)

Enter image details here

I have two classes for showing current details and saving new product for each of the above work

  Public category VMProduct {Public list> Products & gt; Product List {Received; Set; }} Public class product {public string ProductID {get; Set; } Public string product name {get; Set; } Public string Uom1 {get; Set; } Public string Uom2 {get; Set; } Public String ProductCategoryID {Receive; Set; }}   

My problem is that I can display data using the VMProduct.ProductList model but how can I save new product items using the "product" model?

How do I use both models in a sequence? If I use the properties of the "product" model in the VMProduct model then this duplication code is correct?

Can anyone have any solution for this? Thanks in advance

It seems that VMProduct is already a custom view Model I'm mostly guessing by its name), so add a property for the type you need:

  Public category VMProduct {Public listing> Products & gt; {Product list}; Set; } Public product NewProduct {get; Set; }}   

However, as long as I understand something wrong about your UX, it may not even be necessary to be used for render The model that goes on received from a given form does not require the same model, so you can now continue rendering the view using the VMProduct object. , And the form of adding a product is still to be done by the controller. product Add An example could post operation something like:

  public proceedings Jodenjoden () {// check your visual model returns (some Vimpeedent); } [HTTP post] Add products to public action (product newprint) {// Backing Data Store Return Redirect Reduction ("Ed"); }    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -