asp.net mvc - Details view doesn't work mvc 5 -
i have mvc 5 application. follow tutorial getting started asp.net mvc 5
altough when click details, edit or delete http error 400.0 - bad request.
my index view
@foreach (var item in model) { <div class="city"> <h2>@html.displayfor(modelitem => item.announce_publishdate)</h2> <p>@truncate(item.announce_description, 90)</p> <p>@html.actionlink("more", "details", new { id = item.announce_id }) </p></div>}
my details view
<div> <h4>prokirikseis</h4> <hr /> <dl class="dl-horizontal"> <dd> @html.displayfor(model => model.announce_id) </dd> <dd> @html.displayfor(model => model.announce_description) </dd> <dd> @html.displayfor(model => model.announce_publishdate) </dd> </dl> </div> <p> @html.actionlink("edit", "edit", new { id = model.announce_id }) | @html.actionlink("back list", "index")</p>
the controller
public actionresult details(int? id) { if (id == null) { return new httpstatuscoderesult(httpstatuscode.badrequest); } announce announce= db.announce.find(id); if (announce == null) { return httpnotfound(); } return view(announce); }
the model
public class announcements { [key] public string announce_id { get; set; } [display(name = "date")] [datatype(datatype.date)] [displayformat(dataformatstring = "{0:dd-mm-yyyy}", applyformatineditmode = true)] public nullable<system.datetime> announce_publishdate { get; set; } [display(name = "title")] public string announce_description { get; set; } }
what doing wrong? notice brings right id in url. http://localhost:zzzzz/ltest/details/01_2.2 does't bring content. thank you
your action methods accepting parameter typeof int
key in class announcements
string
, not int
. (and url
in question passing value of 01_2.2
details()
method id
null
).
change methods to
public actionresult details(string id)
although recommend change key auto incremented int
Comments
Post a Comment