Neo*_*Neo 1 model-view-controller asp.net-mvc asp.net-mvc-3
对于Index操作我需要传递Guid,但它应该为null,因为我正在检查它是否有编辑或删除操作.
我使用了这样但得到编译错误:Guid不能为null必须是编译时间常量.或运行时错误:
参数字典在'Mapping.Controllers.HomeController中为方法'System.Web.Mvc.ActionResult Index(System.String,System.Guid)'包含非可空类型'System.Guid'的参数'uid'的空条目. ".可选参数必须是引用类型,可空类型,或者声明为可选参数.
public ActionResult Index(string userAction, Guid uid = new Guid() )
{
----
----
}
Run Code Online (Sandbox Code Playgroud)
尝试使用nullable Guid作为参数:
public ActionResult Index(string userAction, Guid? uid = null)
Run Code Online (Sandbox Code Playgroud)
根据您的评论,假设objModel.Id是a Guid,您可以使用:
objModel.Id != default(Guid)
Run Code Online (Sandbox Code Playgroud)
但是,现在了解您的情况,我会寻求themarcuz更好的整体解决方案.
| 归档时间: |
|
| 查看次数: |
5338 次 |
| 最近记录: |