Asp.net mvc 使用ActionLink传递给操作的参数失败
我贴了下面的代码。在控制器端未找到参数值。 空值出现在Asp.net mvc 使用ActionLink传递给操作的参数失败,asp.net-mvc,razor,Asp.net Mvc,Razor,我贴了下面的代码。在控制器端未找到参数值。 空值出现在删除类别(Guid id)处 我的模型代码是正常的,模型中没有错误 public Guid CID { get; set; } [Required] [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] [DataType(
删除类别(Guid id)
处
我的模型代码是正常的,模型中没有错误
public Guid CID { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Text)]
[Display(Name = "Category Name" )]
public string Category { get; set; }
public List<CategoryViewModel> cat;
public CategoryViewModel() {
cat = new List<CategoryViewModel>();
}
我的控制器代码是:这是一个我正在传递参数的控制器。但id的值始终保持不变
public PartialViewResult DeleteCategory(Guid? id)
{
CategoryViewModel cc = new CategoryViewModel();
ssp_category_ID_Result cs;
try
{
cs = new GenericList<ssp_category_ID_Result(sce.ssp_category_ID(id).GetEnumerator()).Single();
cc.Category = cs.CategoryName;
cc.CID = cs.CID;
return PartialView("_DeleteCategoryPartial", cs);
}
catch(Exception ex){
ModelState.AddModelError("",ex.Message);
}
return PartialView("_DeleteCategoryPartial");
}
[HttpPost]
public ActionResult DeleteCategory(CategoryViewModel cs)
{
try
{
sce.dsp_category(cs.CID);
ModelState.AddModelError("","Deleted");
}
catch (Exception ex) {
ModelState.AddModelError("",ex.Message);
}
return View("Category");
}
public PartialViewResult deleteCegory(Guid?id)
{
CategoryViewModel cc=新的CategoryViewModel();
ssp_类别_ID_结果cs;
尝试
{
cs=new GenericList我认为您使用了错误的重载,您试图使用:
ActionLink(HtmlHelper, String, String, Object, Object)
您应该在何时使用:
ActionLink(HtmlHelper, String, String, String, Object, Object)
因此,请将代码更改为:
@Html.ActionLink("Delete", "DeleteCategory", "Admin", new { id = item.CID }, new{})
为操作生成了什么URL?实际上,原始HTML看起来像什么?item.CID的值是什么?item.CID是特定类别的GUID值。使用@HTML.ActionLink(“删除”、“删除类别”、“管理”,新的{id=item.CID},null)
ActionLink(HtmlHelper, String, String, String, Object, Object)
@Html.ActionLink("Delete", "DeleteCategory", "Admin", new { id = item.CID }, new{})