I have method on m开发者_C百科y Model:
public string GetSubscriptionCode()
{
return String.Format(Name.ToLower().Replace("", "-"));
}
Than when I want to call that method on the view i am getting an error that there is no such method in my model:
<div id="@Model.GetSubscriptionCode()"></div>
Any ideas?
Update: Ooops, I mixed up my models, I put my method in to wrong one... Now i would remove this question if i could
Assuming your view is strongly typed to a model:
@model MyViewModel
where MyViewModel
contains this public method:
public class MyViewModel
{
public string Name { get; set; }
public string GetSubscriptionCode()
{
return String.Format(Name.ToLower().Replace("", "-"));
}
}
you should be able to perfectly fine access it in the view:
<div id="@Model.GetSubscriptionCode()"></div>
Don't worry if Visual Studio underlines it saying that it doesn't exist. Intellisense in views is far from perfect. Simply run your application and it will work as expected.
Maybe it's an extension method so you need to include/import the namespace implementing that extension method.
精彩评论