Flood Gravemind
Flood Gravemind

Reputation: 3801

Obtain the type of view that is calling the controller in MVC4

I know that this question may be flagged as duplicate to this one but my question is I need to obtain some reference not URL for the view that called the Controller action. I need to determine an attribute for the model based on the View with a code such as

public ActionResult Create(message message)
        {
        switch (View.type)
{
case("MSG"):
message.type = 0; // 0 for messages
case("Reminder"):
message.type = 1; // 1 for reminders
}

Upvotes: 1

Views: 58

Answers (1)

cadrell0
cadrell0

Reputation: 17327

I suspect you don't care what View was used, but what previous Controller action got you there. In that case, you should add a field to you Model (or create a ViewModel) to indicate this information.

If you really care what View was used, then you have business logic in your View. This is a bad thing. Don't do that.

Upvotes: 1

Related Questions