I have customer model
public class Customer
{
public Customer()
{
this.SystemValues = new HashSet<SystemValue>();
}
public string Name { get; set; }
public Nullable<System.Guid> GUID { get; set; }
public int Id { get; set; }
public virtual ICollection<SystemValue> SystemValues { get; set; }
}
and systemValue model
public class SystemValue
{
public int CustomerId { get; set; }
public int SystemValueId { get; set; }
public Nullable<int> SystemValueCategoryId { get; set; }
public string SystemValueType { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string TextValue { get; set; }
public Nullable<int> IntValue { get; set; }
public Nullable<double> FloatValue { get; set; }
public byte[] BlobValue { get; set; }
public Nullable<System.DateTime> DateTimeValue { get; set; }
public Nullable<bool> BooleanValue { get; set; }
public Nullable<int> LookupValueId { get; set; }
public Nullable<int> LookupValueGroupId { get; set; }
public Nullable<bool> IsReadonly { get; set; }
public bool IsHidden { get; set; }
public int Id { get; set; }
public virtual Customer Customers { get; set; }
}
in which way I could show a link in CustomerView(CustomersController) foreach customer that redirect to the SystemValuesView(SystemValuesController) with related to this customer SystemValues?
I found out one way - redirect to this controller's action with parameter.
public ActionResult ViewSystemValues(int? id)
{
return RedirectToAction("Index", "SystemValues", new {id});
}
But I'm sure there must be smarter way.
#for(int i = 0; i < Model.yourcustomerlist.Count(); i++)
{
<tr>
<td>
<a class="btn btn-primary" href="#Url.Action("Index", "SystemValues", new { id = Model.yourcustomerlist[i].CustomerId })">
<b>Go to system values</b>
</a>
</td>
</tr>
}
I hope I understood you correctly.
This code should go in the view. The view should be strongly typed to a model.
Code is if you want a button that redirects to the index view of the SystemValues controller, with the CustomerId as input. You should change "yourcustomerlist" to the list containing the customer information. If it's not part of a table, remove the table-related tags (<td> and <tr>).
Related
I have four models ( Item, Fabric, Production, stock)
and i want to get value of stock by item ID like that :
<table class="table-responsive">
<tr>
<td>Color</td>
<td>Size</td>
<td>Quantity</td>
</tr>
<tbody class="StockTbody"></tbody>
</table>
so that the values for the color and size are not repeated.
fabric Model:
public class Fabric
{
public int ID { get; set; }
public string FabricName { get; set; }
//[DataType(DataType.Date)]
[Display(Name = "Color")]
public int ColorID { get; set; }
public string Code { get; set; }
public virtual Colors Colors { get; set; }
public virtual List<FabricStore> fabricStore { get; set; }
public virtual List<Production> production { get; set; }
}
Color Model:
public class Colors
{
public int ID { get; set; }
[Display(Name ="Color")]
public string ColorName { get; set; }
public virtual List<Fabric> fabric { get; set; }
public virtual List<OrderDetail> OrderDetails { get; set; }
}
Item Model :
public class Item
{
public int ID { get; set; }
[Display(Name = "Item")]
public string ItemName { get; set; }
public int code { get; set; }
[Display(Name ="Collection")]
public Nullable<int> CollectionID { get; set; }
[Display(Name = "Category")]
public Nullable<int> CategoryID { get; set; }
public string Image { get; set; }
public string BarcodeImage { get; set; }
public string Barcode { get; set; }
public int NumberOfDraft { get; set; }
public decimal SectoralSellingPrice { get; set; }
public decimal wholesalePrice { get; set; }
public decimal discountPrice { get; set; }
public decimal wholesalevariegated { get; set; }
public decimal DesignCost { get; set; }
public int three { get; set; }
public virtual List<Production> production { get; set; }
public virtual Collection collection { get; set; }
public virtual Categories categories { get; set; }
public virtual List<OrderDetail> orderDetail { get; set; }
}
and this is stock model:
public class Stock
{
public int ID { get; set; }
public int ProductionID { get; set; }
public int SizeID { get; set; }
public int Quantity { get; set; }
public string ShelfNumber { get; set; }
public virtual Production Production { get; set; }
public virtual Size size { get; set; }
public virtual List<StockRemain> stockRemain { get; set; }
}
this is my Controller:
public JsonResult StuckDetails (int ID)
{
var table = (from tb in db.Stocks
where ID == tb.Production.ItemID
select new
{
color = tb.Production.fabric.Colors.ColorName,
ColorId=tb.Production.fabric.ColorID,
size = tb.size.SizeName,
sizeID = tb.SizeID,
//Quantity =
}).Distinct().ToList();
return Json(table, JsonRequestBehavior.AllowGet);
}
the problem is that : i want to sum Quantity
please help
I think you are looking for a group by here:
public JsonResult StuckDetails (int ID)
{
var table = (from tb in db.Stocks
where ID == tb.Production.ItemID
group tb by new
{
tb.Production.fabric.Colors.ColorName,
tb.size.SizeName
} into grp
select new
{
color = grp.Key.ColorName,
size = grp.Key.SizeName,
Quantity = grp.Sum(g => g.Quantity)
});
return Json(table, JsonRequestBehavior.AllowGet);
}
They Key.ColorName property name might vary - I'm not too sure here. Use Intellisense to guide you through it.
I have the following model class:-
public class TMSServer_Validation
{
[Required]
public string ILOIP { get; set; }
}
and the following view :-
#model TMS.ViewModels.ServerJoin
<div >
<span class="f"> ILOIP</span>
#Html.EditorFor(model =>model.Server.ILOIP)
#Html.ValidationMessageFor(model =>model.Server.ILOIP)
</div>
and the following post action method:-
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(ServerJoin sj, FormCollection formValues)
{
//code goes here..
repository.InsertOrUpdateServer(sj.Server, User.Identity.Name, sj.Resource.RESOURCEID);
repository.Save();
return RedirectToAction("Index");
and the following view model class:-
public class ServerJoin
{
public TMSServer Server { get; set; }
public Resource Resource { get; set; }
public Technology Technology { get; set; }
public ComponentDefinition ComponentDefinition { get; set; }
}
but whenever i want to edit an object the model state will be False, and the error message indicates that the ILOP field is required, although there is a value for it on the view?
So what is causing this problem ?
UPDATE
Th model class is :-
[MetadataType(typeof(TMSServer_Validation))]
public partial class TMSServer
{
public TMSServer()
{
this.TMSServers1 = new HashSet<TMSServer>();
this.TMSVirtualMachines = new HashSet<TMSVirtualMachine>();
}
public int ServerID { get; set; }
public Nullable<int> ServerModelID { get; set; }
public int DataCenterID { get; set; }
public string ILOIP { get; set; }
public int RackID { get; set; }
public Nullable<int> StatusID { get; set; }
public Nullable<int> BackUpStatusID { get; set; }
public int RoleID { get; set; }
public Nullable<int> OperatingSystemID { get; set; }
public Nullable<int> VirtualCenterID { get; set; }
public string Comment { get; set; }
public byte[] timestamp { get; set; }
public long IT360SiteID { get; set; }
public virtual DataCenter DataCenter { get; set; }
public virtual OperatingSystem OperatingSystem { get; set; }
public virtual ServerModel ServerModel { get; set; }
public virtual Technology Technology { get; set; }
public virtual TechnologyBackUpStatu TechnologyBackUpStatu { get; set; }
public virtual TechnologyRole TechnologyRole { get; set; }
public virtual TechnologyStatu TechnologyStatu { get; set; }
public virtual TMSRack TMSRack { get; set; }
public virtual ICollection<TMSServer> TMSServers1 { get; set; }
public virtual TMSServer TMSServer1 { get; set; }
public virtual ICollection<TMSVirtualMachine> TMSVirtualMachines { get; set; }
}
I am looking to display Hole_Num value from my Holes class, in my RoundDetails class within the RoundDetails/Create razor view.
Here is my Holes class:
public partial class Hole
{
public Hole()
{
this.RoundDetails = new HashSet();
}
public int HoleId { get; set; }
public int FacilityId { get; set; }
public int CourseId { get; set; }
public int TeeTypeId { get; set; }
public int Hole_Num { get; set; }
public int Yardage { get; set; }
public byte Par { get; set; }
public short Handicap { get; set; }
public virtual ICollection<RoundDetail> RoundDetails { get; set; }
public virtual TeeType TeeType { get; set; }
}
Here is my RoundDetails class:
public partial class RoundDetail
{
public int RoundId { get; set; }
public int GolferId { get; set; }
public int FacilityId { get; set; }
public int CourseId { get; set; }
public int TeeTypeId { get; set; }
public int HoleId { get; set; }
public decimal Differential { get; set; }
public Nullable Date { get; set; }
public byte Score { get; set; }
public Nullable Putts { get; set; }
public Nullable GIR { get; set; }
public Nullable FIR { get; set; }
public Nullable Up_And_Down { get; set; }
public Nullable Par_Save { get; set; }
public Nullable Sand_Save { get; set; }
public Nullable Driving_Distince { get; set; }
public Nullable Proximity { get; set; }
public Nullable Green_Fee { get; set; }
public virtual Course Course { get; set; }
public virtual Facility Facility { get; set; }
public virtual Golfer Golfer { get; set; }
public virtual Hole Hole { get; set; }
public virtual TeeType TeeType { get; set; }
}
Here is my razor view:
<td>
#Html.LabelFor(model => model.Hole.Par)
</td>
How am I able to populate this label with the Par information from the Holes table? I assume that some manipulation with the Create method of the RoundDetailController or creating a ViewModel of some sort is the way to go but I"m not sure which one or how start either. Please help!
My web page / view will have 1 to many import records.
Within each import record will be 0 to many of the following:
Purchase Orders
Shipping Containers
Products
Invoices
I have coded my view model as follows:
namespace LemansCorpIntranet.Models
{
public class ImportWebViewModel
{
public string button { get; set; }
public string status_filter { get; set; }
public string import_id_filter { get; set; }
public DateTime date_filter { get; set; }
public string vendor_filter { get; set; }
public string port_filter { get; set; }
public string whse_filter { get; set; }
public Boolean not_released_filter { get; set; }
public int release_gap { get; set; }
public List<import_row> import_rows;
}
public class import_row
{
public string update_switch { get; set; }
public string id { get; set; }
public IEnumerable<SelectListItem> ship_via { get; set; }
public string broker_number { get; set; }
public string voyage { get; set; }
public string vessel { get; set; }
public decimal shipment_value { get; set; }
public int cartons { get; set; }
public decimal weight { get; set; }
public decimal volume { get; set; }
public string clearance_port { get; set; }
public string warehouses_in_shipment { get; set; }
public string payment_type { get; set; }
public string insurance { get; set; }
public DateTime ship_date { get; set; }
public DateTime close_date { get; set; }
public DateTime customs_date { get; set; }
public string customs_entry { get; set; }
public DateTime pl_2_whse_date { get; set; }
public DateTime estimated_arrival_date { get; set; }
public DateTime wire_transfer_request_done_date { get; set; }
public DateTime approved_broker_bill_date { get; set; }
public DateTime product_released_date { get; set; }
public List<Invoice> Invoices;
public List<PurchaseOrder> PurchasOrders;
public List<Product> Products;
public List<Container> Containers;
}
public class Invoice
{
public string invoice_number { get; set; }
}
public class PurchaseOrder
{
public string id { get; set; }
public string whse { get; set; }
public string vendor_code { get; set; }
public string vendor_name { get; set; }
}
public class Product
{
public int line_number { get; set; }
public string description { get; set; }
}
public class Container
{
public int line_number { get; set; }
public int size { get; set; }
public string id { get; set; }
public string seal { get; set; }
public DateTime received_date { get; set; }
public int cartons { get; set; }
}
}
Is the above OK? Are the classes nested correctly?
I can get the view to display my data from the server correctly, but when I "post" the form the data in the nested classes is null.
I believe this is because the input controls don't get built as they need to be.
My view is similar to the following:
<table>
<% if (Model.import_rows != null)
{ %>
<% for (int row = 0; row < Model.import_rows.Count; row++)
{ %>
<tr><td>
<%=Html.HiddenFor(x=>x.import_rows[row].id) %>
<%=Html.TextBoxFor(x => x.import_rows[row].id)%>
</td>
</tr>
<% } %>
<% } %>
</table>
Any suggestions would be greatly appreciated....
Update: I have changed my view to include "hiddenFor" items.
"import_rows" is no longer null in the controller, but the count is "0".
I still must be missing something.....
Thanks in advance.
I was attempting to pass the viewmodel in a RedirectToAction..
Have discovered this doesn't work that way.
Thanks everyone for your assistance.
I have a Model that named word.
this is my word model
public class Word : BaseFieldsTables
{
int ID { get; set; }
string Name { get; set; }
Guid UniqID { get; set; }
DateTime CreatedDate { get; set; }
byte[] RowVersion { set; get; }
public string Text { get; set; }
public virtual Category Category { get; set; }
public int CategoryID { get; set; }
public virtual Language Language { get; set; }
public int LanguageID { get; set; }
public virtual ICollection<Picture> Pictures { get; set; }
[InverseProperty("MainWord")]
public virtual ICollection<RelationshipBetweenWords> MainWords { get; set; }
[InverseProperty("RelatedWord")]
public virtual ICollection<RelationshipBetweenWords> RelatedWords { get; set; }
}
word has a category and language and...
for example this is my language model
public class Language : BaseFieldsTables
{
int ID { get; set; }
string Name { get; set; }
Guid UniqID { get; set; }
DateTime CreatedDate { get; set; }
byte[] RowVersion { set; get; }
public virtual ICollection<Word> Words { get; set; }
}
i have word word viewmodel like this
public class WordViewModel
public string Name { get; set; }
public IList<SelectListItem> Categories { set; get; }
[HiddenInput(DisplayValue = false)]
public int SelectedCategoryID { set; get; }
public IList<SelectListItem> Languages { set; get; }
[HiddenInput(DisplayValue = false)]
public int SelectedLanguageID { set; get; }
}
and this my controller
public ActionResult Index(
{
IList<Word> list = _wordService.GetAll();
}
i want to get all word and map(auotomapper) to my WordViewModel with languagename and category name and return in my view please help me if i have to change my wordviewmodel or... and how to map.tnx
oh i found it
public ActionResult Index()
{
var orders = _respository.GetAll();
AutoMapper.Mapper.CreateMap<Order, OrderDto>()
.ForMember(dest => dest.OrderNumber, opt => opt.MapFrom(src => src.OrderNo))
.ForMember(dest => dest.OrderItemsDto, opt => opt.Ignore());
var model = AutoMapper.Mapper.Map<IEnumerable<Order>, IEnumerable<OrderDto>>(orders);
return View(model);
}
//Razor View Code
<h2>Orders</h2>
<table>
<tr>
<th>Order Number</th>
<th>Name</th>
<th>Total</th>
</tr>
#foreach (var item in Model)
{
<tr>
<td>#item.OrderNumber</td>
<td>#item.CustomerName</td>
<td>$#item.Total</td>
</tr>
}
</table>