0

I am currently doing an MVC application in .NET.

As for now, within my _Layout.cshtml page i have a login modal that is made with bootstrap. (I want to use a specific model with this modal)

The thing is, i have already passed a model to my _Layout.cshtml page, which means that i need to separate my modal from the _Layout.cshtml page to another view, in which i there will be able to invoke my model.

This leads me to my question:

How do i separate my modal to another view, and still be able to call it in my _Layout.

Assumption: I could just toss my modal to my index view, but that would just move the problem to my index view instead.

Jeppe Christensen
  • 1,680
  • 2
  • 21
  • 50
  • 1
    In your layout use `@Html.Action(...)` to call a `[ChildActionOnly]` method that returns a partial view of your modal (your `_Layout.cshtml` file should not contains a `@model ...` statement unless its a base view model used by all view that use that layout) –  Feb 27 '17 at 23:24
  • Thank you for your answer, makes sense now! – Jeppe Christensen Feb 27 '17 at 23:28
  • @StephenMuecke you are far from being fair with me. I see you mocking every single post i make. I feel that you are getting personal with me – Jeppe Christensen Feb 27 '17 at 23:37
  • What are you talking about? And what make you think I am _mocking_ you? –  Feb 27 '17 at 23:40
  • You are marking my question a duplicate. You did the same on my previous question. - it is furthermore not the same question. – Jeppe Christensen Feb 27 '17 at 23:44
  • It is a duplicate - it shows you how to handle this (as per my previous comment - i.e. use `@Html.Action()` to call a server method). There is no point repeating the same answer to the same questions over and over again (which is the purpose of marking questions as duplicates). Just because your creating a partial for a form as opposed to creating a partial for a menu as per the dupe makes no difference. –  Feb 27 '17 at 23:47

0 Answers0