c# - MVC-5: Show Full Names -
c# - MVC-5: Show Full Names -
i show fullname computed property @ top of view. can see fullname property when @ autos log. lambda look used in html helper shows property name, not data. there way display info log seems show available?
update:
the finish view:
@model ienumerable<slamjammersdata.model.attendances> @{ viewbag.title = "rosters"; } <div class="container container-fluid"> <div class="panel panel-info"> <div class="panel-body"> <div class="container"> @using (html.beginform("index", "attendances", formmethod.get)) { <div class="row"> <div class="col-md-4"> <p> <h3>attendances player: @html.displaynamefor(model => model.fullname) </h3> </p> </div> <div class="col-md-4"> <p> <h4>attendances recorded: @model.count() </h4> </p> </div> </div> } </div> </div> </div> </div> <div class="container"> <div class="row"> <div class="col-md-2"> <p> @html.displaynamefor(model => model.type) </p> </div> <div class="col-md-2"> <p> @html.displaynamefor(model => model.attendancedate) </p> </div> <div class="col-md-2"> <p> @html.displaynamefor(model => model.comments) </p> </div> </div> @foreach (var item in model) { <div class="row table-striped"> <div class="col-md-2"> <p> @html.displayfor(modelitem => item.type) </p> </div> <div class="col-md-2"> <p> @html.displayfor(modelitem => item.attendancedate) </p> </div> <div class="col-md-2"> <p> @html.displayfor(modelitem => item.comments) </p> </div> <div class="col-md-1"> <p> <input class="btn btn-xs btn-info" type="button" value="details" onclick=" location.href = '@url.action("details", "attendances", new {id = item.id}, null)' "/> </p> </div> <div class="col-md-1"> <p> <input class="btn btn-xs btn-info" type="button" value="edit" onclick=" location.href = '@url.action("edit", "attendances", new {id = item.id}, null)' "/> </p> </div> <div class="col-md-2"> <p> <input class="btn btn-xs btn-success" type="button" value="add new attendance" onclick=" location.href = '@url.action("create", "attendances", new {enrollments_attendance = item.enrollments_attendance}, null)' "/> </p> </div> <div class="col-md-1"> <p> <input class="btn btn-xs btn-danger" type="button" value="delete" onclick=" location.href='@url.action("delete", "attendances", new {id = item.id}, null)' " /> </p> </div> </div> } </div>
the controller:
public actionresult index(int? id ) { //get rosters , attendance records iqueryable<attendances> attendances = db.attendances .where(a => a.enrollments_attendance == id) .include(e => e.enrollments.individuals) .orderbydescending(a => a.attendancedate); viewbag.enrollmentid = id; var sql = attendances.tostring(); homecoming view(attendances.tolist()); }
the model:
namespace slamjammersdata.model { public class attendances { public int id { get; set; } [required] [stringlength(15)] public string type { get; set; } [datatype(datatype.date)] [displayformat(dataformatstring = "{0:mm-dd-yyyy}", applyformatineditmode = true)] public datetime attendancedate { get; set; } [stringlength(255)] public string comments { get; set; } [display(name="enrollments")] public int enrollments_attendance { get; set; } public virtual enrollments enrollments { get; set; } [notmapped] public string fullname { { var player = enrollments.individuals.firstname + " " + enrollments.individuals.lastname; homecoming player; } } } }
i not sure if ienumerable or not, here showing in debugger: screenshot of debugger's auto log
since model ienumerable<slamjammersdata.model.attendances>
, fullname
property of attendances
, can't utilize fullname
property outside foreach
block you're trying do. assuming value of fullname
same, can utilize viewbag
. alter controller method below
public actionresult index(int? id ) { //get rosters , attendance records iqueryable<attendances> attendances = db.attendances .where(a => a.enrollments_attendance == id) .include(e => e.enrollments.individuals) .orderbydescending(a => a.attendancedate); viewbag.enrollmentid = id; viewbag.fullname = ...; // logic fullname here var sql = attendances.tostring(); homecoming view(attendances.tolist()); }
and display total name in view follows
@using (html.beginform("index", "attendances", formmethod.get)) { <div class="row"> <div class="col-md-4"> <p> <h3>attendances player: @viewbag.fullname </h3> </p> </div> <div class="col-md-4"> <p> <h4>attendances recorded: @model.count() </h4> </p> </div> </div> }
c# asp.net-mvc razor
Comments
Post a Comment