无法访问操作过滤器中的本地变量:对象不包含错误定义
菜鸟 MVC 问题!考虑以下我用于操作过滤器的
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
var model = filterContext.Controller.ViewData.Model;
}
var 模型包含我想要访问的部分。我知道它在那里,因为当我在该点断点时我可以看到。
但是,当我想要:
string tempStr = model.Companydetails.Address;
我收到“对象不包含定义”错误。对我在这里缺少什么有任何想法。预先感谢您的宝贵时间。
编辑
:@Leniel Macaferi。斯克里枪!
Noob to MVC question! Consider the following I'm using for an action filter
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
var model = filterContext.Controller.ViewData.Model;
}
var model contains a section I want to access. I know it's there because when I breakpoint at that point I can see.
However, when i want to :
string tempStr = model.Companydetails.Address;
I get ' object does not contain a definition ' error. Any thoughts to what im missing here. Thanks in advance for your time.
S
EDIT: @Leniel Macaferi. Scr shot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不是吗:
我可以看到Address1为空。我看不到地址属性。您能确认有一个 Address 属性吗?
错误:对象不包含定义,通常与代码中错误键入的变量名称有关。请注意,您在代码中使用了
Companydetails
,而它应该是CompanyDetails
,且详细信息中包含大写 D。Wouldn't it be:
I can see that Address1 is null. I cannot see the Address property. Can you confirm that there is an Address property?
The error: object does not contain a definition for, generally is related to wrongly typed variable names in your code. Note that you're using in your code
Companydetails
when it should beCompanyDetails
with an upper case D in Details.