【发布时间】:2016-07-01 16:07:27
【问题描述】:
所有类似的主题都解决了,但我找不到和我类似的错误。
型号:
public class CountriesViewModel
{
public int BuffId { get; set; }
public string CountryId { get; set; }
public string Name { get; set; }
}
查看:
@model List<BTGHRM.Models.CountriesViewModel>
@{
WebGrid grid = new WebGrid(Model, canSort: false, rowsPerPage: 15);
int row = 0;
}
@if (Model.Any())
{
@grid.GetHtml(
tableStyle: "table",
headerStyle: "table_HeaderStyle",
footerStyle: "table_PagerStyle",
rowStyle: "table_RowStyle",
alternatingRowStyle: "table_AlternatingRowStyle",
selectedRowStyle: "table_SelectedRowStyle",
columns: grid.Columns(
grid.Column("Name", @Resources.Localization.country, format: @<text>
<span class="display-mode"><label id="NameLabel">@item.Name</label></span>
@Html.TextBox("Model[" + (++row - 1).ToString() + "].Name", (object)item.Name, new { @class = "edit-mode" })
</text>, style: "p40"),
grid.Column("", "", format: @<text>
@Html.Hidden("Model[" + (row - 1).ToString() + "].BuffId", (object)item.BuffId, new { @class = "edit-mode" })
</text>, style: "p13"),
grid.Column("", "", format: @<text>
<a href="DeleteCountryRecord/@item.BuffId" id="@item.BuffId" class="link_button delete-button display-mode">@Resources.Localization.delete</a>
</text>)
)
)
}
我想通过在 action 方法中发送它的 id (buffId) 来删除行:
public ActionResult DeleteCountryRecord(int BuffId)
{
using (var db = new HRMEntities())
{
Country RemovableLine = db.Countries.Find(BuffId);
try
{
db.Countries.Remove(RemovableLine);
}
catch
{
TempData["Message"] = App_GlobalResources.Localization.error;
}
db.SaveChanges();
}
return RedirectToAction("CountryCodes");
}
我所有的 Id 都正确,但我有错误
参数字典包含“BTGHRM.Controllers.AdministrationController”中方法“System.Web.Mvc.ActionResult DeleteCountryRecord(Int32)”的不可为空类型“System.Int32”的参数“BuffId”的空条目。可选参数必须是引用类型、可空类型或声明为可选参数。 参数名称:参数
但是在点击按钮生成的链接中可以看到,那个id是正确的:
http://localhost:59763/Administration/DeleteCountryRecord/17
我的问题可能是什么?
【问题讨论】:
标签: c# asp.net-mvc dictionary