Cannot access local var in action filter: object does not contain a definition for error
Noob to MVC question! Consider t开发者_运维技巧he 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!
Wouldn't it be:
string tempStr = model.CompanyDetails.Address1;
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 be CompanyDetails
with an upper case D in Details.
精彩评论