Tuesday, 15 March 2011

c# - How to get a comma between items in the View? -


In my view, I want to separate guest id with a comma but I do not know how to Looks like 16 and 17 different guests from IDs are misleading.

Enter image details here

My model looks like this Is:

  public class guest {{key} public {}; Set; } // Reserved PR Intel 32? Reservation {Come; Set; }}  

The view controller looks like this:

  Public Performance Index () {Return View (_reservationrepository.GetAllReservations ()); } Public IQueryable GetAllReservations () {Return db.Reservations.Include (r = & gt; r.spot). Include (r = & gt; r.User). (R = & gt; R.Greats); }  

My view looks like this:

  @forach (various items in the model) {& lt; Tr & gt; & Lt; TD & gt; @html DisplayFor (Model Itam => Objects Grandes) & lt; / Td> & Lt; / TR & gt; }  

How do I separate guest IDs by a comma?

If you have a collection of guest objects in your view (let's get it now < Code> Model.Guests ), you can include the ID in a delimited string:

  string.Join (",", Model.Guests.Select (G = & gt; g.GuestId))  

Or, depending on the context of the visual model (if it is for viewing purposes and not really a business model) You can also put it on the model:

  public string over Iids {get {return string.join ( ",", please. Select (G = & gt; Jikgustaidi)); }}  

and force the view of that property:

@ Model.GuestIDs

No comments:

Post a Comment