Compil3
Compil3

Reputation: 137

Partial View not showing up MVC

I need to create a partial view for a calendar and it's not showing up I don't know why. I try to display the partial view with:

<div>
@{
    await Html.RenderPartialAsync("_Calendar");
}

I don't know what the problem is...If I made a button in my navigation bar with:

<a class="nav-link text-dark" asp-area="" asp-controller="Booking" asp-action="Calendar">Calendar</a>

and then in the BookingController simply do this:

 public class BookingController : Controller
{
    public IActionResult Index()
    {
        return View();
    }

    public ActionResult Calendar()
    {
        return View("_Calendar");
    }
}

There it shows up..but not in the Booking Index like it should. Here are some images: enter image description here

The red rectangle is where I want the _Calendar to be. This Image if what shows if I go to _Calendar using the nav bar: enter image description here

The _Calendar partial view is in my shared folder. Let me know if you need any more information.

So I added a

TEST

inside the _Calendar and that shows up but the calender does not: enter image description here

Upvotes: 0

Views: 1111

Answers (1)

Yiyi You
Yiyi You

Reputation: 18139

If you have js code in _Calendar,the page which refernces _Calendar will not load the js code.And you need to put the js code of _Calendar into the page which refernces _Calendar. Here is a demo worked. Main.cshtml(reference a partial view):

@{
    ViewData["Title"] = "Main";
}

<h1>Main</h1>
<div style="height:400px;width:400px;border:1px solid red;">
    <partial name="_partial1" />
</div>
@section scripts{
    <script type="text/javascript">
        $("#div1").text("Hello World!");
    </script>
}

_partial1.cshtml(in Shared folder):

<div id="div1">
</div>

result:

enter image description here

Upvotes: 1

Related Questions