Haxed
Haxed

Reputation: 2917

How to write an action method in a controller to reference a partial view?

I have written an action method in the ReservationController class. To get this code to work I should move the GetCoreTab file to the Reservation folder. I do not want to do that since I give the path of the GetCoreTab file in the ReservationController class. I want to give the path, such that the code for the GetCoreTab method would work from the Reservation controller class.

Structure:

enter image description here

Code:

        public PartialViewResult GetCoreTab()
    {
        return PartialView("Tabs/GetCoreTab");
    }

HTML:

<a href="<%= Url.Action("GetCoreTab", "Reservation") %>" class="a">
                <b>
                    <div id="home" class="menu">
                    </div>
                </b>
            </a>

Any ideas?

Thanks

Upvotes: 0

Views: 333

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

You could specify the path to the partial:

public PartialViewResult GetCoreTab()
{
    return PartialView("~/Views/Shared/Tabs/GetCoreTab.ascx");
}

Upvotes: 1

Related Questions