我有一個MVC 5應用程序。我跟進本教程Getting Started with ASP.NET MVC 5詳細信息視圖不起作用mvc 5
當我單擊詳細信息,編輯或刪除時,我仍然得到HTTP錯誤400.0 - 錯誤的請求。
我的索引視圖
@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>}
我詳細查看
<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 to List", "Index")</p>
控制器
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);
}
模型
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; }
}
我做錯了什麼?我注意到它在URL中帶來了正確的ID。 http://localhost:zzzzz/ltest/Details/01_2.2但它不會帶來內容。 謝謝
'01_2.2'不是有效的int ... –
感謝您回覆,我嘗試使用可以說106的其他id。但它顯示「類型'System.ArgumentException'的異常發生在EntityFramework.dll中,但未在用戶代碼中處理 附加信息:其中一個主鍵值與實體中定義的類型不匹配。請參閱inn呃細節異常「我在我的模型中將字符串更改爲int,但它不起作用。 – touinta