I am accessing data in the controller using a WCF service.
Public Performance Index () {DataRerieveClient _proxy = New DataRerieveClient (); Var orderDetails = _proxy.GetProductDetails (zero); See Return (); }
How to view and see orderdetails
among them from viewers and see them.
Edit: / Strong>
I have a model:
public order orderdetails {public int Order id {get; Set; } Public int ProductId {get; Set; } Receive Public Decimal Unitpits { Set; } Public int quanity {get; Set; } Public Decimal Discount {get; Set; }}
and _proxy.GetProductDetails (zero)
returns from the list & lt; ServiceType.OrderDetails & gt;
- Do I need a local model in this scenario?
- How do I display a list value in the table in my view?
Edit2:
public class AutoMapperConfig {public static void configure () {Mapper.Map (ServiceOrders.OrderDetails, NorthWindMVCWCF .Models.OrderDetails); }}
Error getting now
'NorthWindMVCWCF.ServiceOrders.OrderDetails' is a' type ', which is not valid in the context' NorthWindMVCWCF's models are Order details' is a 'type', which is not valid in context
I view model'd like to make, I'll do it as follows:
Create visual models
public class OrderDetailViewModel {public int orderId { get; Set; } Public int ProductId {get; Set; } Receive Public Decimal Unitpits { Set; } Public int quanity {get; Set; } Public Decimal Discount {get; Set; }} Public Class Order DevelopPivo Model {Public Order DeviableView module () {Order Details = New List & lt; Order detailswalmelmodel & gt; (); } Public List & amp; Lt; Order Details View Model & gt; Order-details {get; Set; }}
Manual Projection
You can create a OrderDetails
visual model and for example, manually You can create a project from:
var orderDetailsViewModel = New OrderDetailsViewModel (); foreach (var orderdetail in ORDERDETAILS) {orderDetailsViewModel.Add (New OrderDetailsViewModel {OrderID = orderDetail.OrderId, productid = orderDetail.ProductId, UnitPrice = orderDetail.UnitPrice, quanity = orderDetail.quantity, Discount = orderDetail.Discount}); AutoMapper Optional Launch Install the Automaker, run the following from the Package Manager console:
Install - Package Automaker
< P> Make App_Start
in the Auto_martConfig.cs
folder with the mapping, like the following: Public Static Class AutomationPerfect {Public Fixed Zero Configure Do (Mapper) Creatives and lieutenants; Order details, order dependent module & gt; (); }}
Call the configuration method in your global ASX:
Secure void Application_Start () {... AutoMapperConfig.Configure (); ...}
Then map to your controller:
var orderDetailsViewModel = New OrderDetailsViewModel (); OrderDetailsViewModel.OrderDetails = Mapper Map & lt; List & lt; Order-Details & gt ;, List & lt; Order DetailsWire Module & gt; & Gt; (OrderDetails);
Matt mapping is globally defined and can be reused within your app, so I like to use an automaker approach.
Revert your visual model
Your visual model will then be refunded as follows:
Return view (OrderDetailsViewModel);
@ModelEducationViewModel
Then output the properties as follows, I've included only the OrderId
but you can add the field in the same way:
Comments
Post a Comment