John
John

Reputation: 3945

error accessing model from view

So bit too late in the project to be at this but i'm tidying up my project to try and refine a error I am receiving. Where I was using some of my model classes for many methods in my HolidayCotroller, So im trying to just run one method from one model. renamed all the files and everything seems to be ok except for my index method

In my View for Index im using @model HolidayBookingApp.Models.IndexModel

but when i click on the below link in the UI:

<p>
    @Html.ActionLink("Holidays Remaining", "HolidaysRemaining")
</p>

the error states:

The model item passed into the dictionary is of type 'HolidayBookingApp.Models.IndexModel', but this dictionary requires a model item of type 'HolidayBookingApp.Models.HolidaysRemainingModel'

So I change the model to:

@model HolidayBookingApp.Models.HolidaysRemainingModel

but it is still giving me the same error msg.

So in my IndexModel.cs i created a new instance of the previous HolidayremainingModel.cs

HolidaysRemainingModel model = new HolidaysRemainingModel();

what now?

Upvotes: 0

Views: 52

Answers (1)

Cris
Cris

Reputation: 13341

use this

@Html.ActionLink("Holidays Remaining", Model.model)

instead of your previous code

@Html.ActionLink("Holidays Remaining", "HolidaysRemaining")

Upvotes: 2

Related Questions