Search code examples
asp.net-mvcannotations

View can't access Model MVC


I have a Controller that return a view with a model such as :

    public ActionResult AddSetStory()
    {
        StoryModel sm = new StoryModel();

        return View(sm);
    }

with model as :

namespace AStoryToTell.Views.Stories.StoriesModel
{
    public class StoryModel
    {
        public int IDStory { get; set; }
        public int IDUser { get; set; }
        public string Title { get; set; }
        public string StoryDescription { get; set; }
        public string StoryText { get; set; }
        public string ImagePath { get; set; }
        public IEnumerable<string> Tags { get; set; }
        public string Base64File { get; set; }
        public string FileName { get; set; }
        public string tagsString { get; set; }

    }
}

but i cannot access it through my view

enter image description here

Even though I have the @model annotation as first line in my view :

@model AStoryToTell.Views.Stories.StoriesModel.StoryModel

What am I missing here ? Shouldn't Model be strongly typed as class StoryModel ?? What i don't understand is why it is not recognize by VS 2013 ?

Although if i do this :

<script>
    var someVariable = '@Model.tagsString';
    console.log(someVariable);
</script>

It will log what i've put in my model as attribute tagsString ..


Solution

  • You've probably solved the problem but the exact same thing happened to me and I restarted visual studio (2013 Professional) and the issue got resolved.

    Thought I'd post this for people who might stumble in here in the future.