Using partial views in ASP.net MVC 4

后端 未结 2 737
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 09:33

I have recently started playing around with ASP.net MVC (4), but I can\'t wrap my head around this one issue I\'m having. I\'m sure it\'s easy when you know it.

I\'m

相关标签:
2条回答
  • 2020-12-04 09:41

    Change the code where you load the partial view to:

    @Html.Partial("_CreateNote", new QuickNotes.Models.Note())
    

    This is because the partial view is expecting a Note but is getting passed the model of the parent view which is the IEnumerable

    0 讨论(0)
  • 2020-12-04 09:47

    You're passing the same model to the partial view as is being passed to the main view, and they are different types. The model is a DbSet of Notes, where you need to pass in a single Note.

    You can do this by adding a parameter, which I'm guessing as it's the create form would be a new Note

    @Html.Partial("_CreateNote", new QuickNotes.Models.Note())
    
    0 讨论(0)
提交回复
热议问题