c# - displaying last record in the database asp.net mvc -
i want display last record of reference of model client:
public class client { public int clientid { get; set; } [required] public string portfolio { get; set; } public int alterid { get; set; } public virtual alter alter { get; set; }
i try create partial view first , create partialmodel. wondering if property of model object client:
public partial class partialmodel { public client client { get; set; } }
could tell me if right method partial_view , how can retrieve last record of client.
here way retrieve , show reference of client:
@model ienumerable<gestion_restrictions.models.client> @foreach (var item in model) { <tr> <td> @html.displayfor(modelitem => item.portfolio) </td> <td> @html.displayfor(modelitem => item.alter.alter_name) </td> }
but how can in create view of client , displaying last record.
<div class="editor-label"> @html.labelfor(model => model.portfolio) </div> <div class="editor-field"> @html.editorfor(model => model.portfolio) @html.validationmessagefor(model => model.portfolio) </div> <div class="editor-label"> @html.labelfor(model => model.alterid, "alter") </div> <div class="editor-field"> @html.dropdownlist("alterid", string.empty) @html.validationmessagefor(model => model.alterid) </div> <input type="submit" value="envoyer" />
thank you!
first of all, don't need partial model this. in case above, model , partial model same, it's 1 more level deep.
here's basic idea of need:
- create partial view accept model of client.
- write database code, or wather code fetch clients server return last record.
i can't provide sample code don't show how retrieve data. if have list do: list.last();
- pass item retrieved in point 2 partial view.
when you're in mvc views, along lines should possible:
@model list<client> <div> @html.partial("mypartialview", model.last()) </div>
note, code untested should working. should started anyway.
as alternative can use viewbag. in code behind like:
viewbag.mylastrecord = , here latest record.
in view, can use:
@html.partial("mypartialview", viewbag.mylastrecord)
Comments
Post a Comment