Fluent Nhibernate 他的参数字典包含参数的空条目
Fluent Nhibernate he parameters dictionary contains a null entry for parameter
项目,我得到一个错误问题是;
“参数字典包含 'BlogNewCMS.Controllers.HomeController' 中方法 'Void Delete(Int32)' 的不可空类型 'System.Int32' 参数 'Id' 的空条目。一个可选参数必须是引用类型、可空类型或声明为可选参数。
参数广告:参数
控制器;
[HttpPost]
public void Delete(int Id)
{
using (var session = FluentNHibernateConnectingAdmin.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
var article = session.QueryOver<Article>().Where(x => x.Id == 3).SingleOrDefault();
session.Delete(article);
transaction.Commit();
}
}
}
第页;
@foreach (var active in Model)
{
using (Html.BeginForm("Delete", "home", FormMethod.Post))
{
<tr role="row" class="gradeA odd">
<td class="sorting_1">@active.UserID</td>
<td>@active.Topic</td>
<td>@active.TopicDetail</td>
<td class="text-center">
<input type="submit" class="btn btn-danger" name="name" value="Sil" />
</td>
</tr>
}
}
路由;
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
您的 Delete 方法需要一个 int
类型的 Id 参数。但是你的表单没有,所以提交的时候没有通过
将名称属性值设置为 "Id"
的表单添加一个输入字段
using (Html.BeginForm("Delete", "home", FormMethod.Post))
{
<tr role="row" class="gradeA odd">
<td class="sorting_1">@active.UserID</td>
<td>@active.Topic</td>
<td>@active.TopicDetail</td>
<td class="text-center">
<input type="submit" class="btn btn-danger" name="name" value="Sil" />
<input type="hidden" name="Id" value="@active.Id" />
</td>
</tr>
}
您可能还想在删除方法中添加一个 return 类型,以便它 return 成为一个响应。
public ActionResult Delete(int id)
{
// to do : Delete
return RedirectToAction("DeletedSuccessfully");
// Assuming you have an action method called DeletedSuccessfully exist
// which shows the "Success message to user
}
项目,我得到一个错误问题是;
“参数字典包含 'BlogNewCMS.Controllers.HomeController' 中方法 'Void Delete(Int32)' 的不可空类型 'System.Int32' 参数 'Id' 的空条目。一个可选参数必须是引用类型、可空类型或声明为可选参数。 参数广告:参数
控制器;
[HttpPost]
public void Delete(int Id)
{
using (var session = FluentNHibernateConnectingAdmin.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
var article = session.QueryOver<Article>().Where(x => x.Id == 3).SingleOrDefault();
session.Delete(article);
transaction.Commit();
}
}
}
第页;
@foreach (var active in Model)
{
using (Html.BeginForm("Delete", "home", FormMethod.Post))
{
<tr role="row" class="gradeA odd">
<td class="sorting_1">@active.UserID</td>
<td>@active.Topic</td>
<td>@active.TopicDetail</td>
<td class="text-center">
<input type="submit" class="btn btn-danger" name="name" value="Sil" />
</td>
</tr>
}
}
路由;
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
您的 Delete 方法需要一个 int
类型的 Id 参数。但是你的表单没有,所以提交的时候没有通过
将名称属性值设置为 "Id"
using (Html.BeginForm("Delete", "home", FormMethod.Post))
{
<tr role="row" class="gradeA odd">
<td class="sorting_1">@active.UserID</td>
<td>@active.Topic</td>
<td>@active.TopicDetail</td>
<td class="text-center">
<input type="submit" class="btn btn-danger" name="name" value="Sil" />
<input type="hidden" name="Id" value="@active.Id" />
</td>
</tr>
}
您可能还想在删除方法中添加一个 return 类型,以便它 return 成为一个响应。
public ActionResult Delete(int id)
{
// to do : Delete
return RedirectToAction("DeletedSuccessfully");
// Assuming you have an action method called DeletedSuccessfully exist
// which shows the "Success message to user
}