0

At the core, I am trying to generate a table with links that can be clicked on a reload of a PartialView. Everything is working except I cannot get the page to stop refreshing. What I would like to do is only load the PartialView inside of the researchDiv. I do have <add key="UnobtrusiveJavaScriptEnabled" value="true" /> in the web.config.

I've changed the view and partialview to now use ajax, but the same issue is occurring and I'm not entirely sure of what to do. If I click a link the entire page refreshes instead of just the htmlContainer.

In my _LayoutDashboard I do have the unobtrusive jscripts, and when the page renders there are 0 Console errors.

<script src="~/Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript">

This is the view

@model Stocks.BLL.ExecutingTrades.Model.WatchList.ExeTradesWatchList

@{
    ViewBag.Title = "WatchList";
    Layout = "~/Views/Shared/_LayoutDashboard.cshtml";
}

<style>
    #customers {
        font-family: Arial, Helvetica, sans-serif;
        border-collapse: collapse;
        width: 20%;
        border: 1px solid black;
    }

        #customers td, #customers th {
            border: 1px solid #ddd;
            padding: 8px;
        }

        #customers tr:nth-child(even) {
            background-color: #f2f2f2;
        }

        #customers tr:hover {
            background-color: #ddd;
        }

        #customers th {
            padding-top: 12px;
            padding-bottom: 12px;
            text-align: left;
            background-color: #04AA6D;
            color: white;
        }

    .float-container {
        border: 3px solid #fff;
        padding: 20px;
    }

    .float-childsmall {
        float: left;
    }

    .float-child {
        width: 80%;
        float: left;
        height: 1000px;
    }
</style>
<script type="text/javascript" src="https://s3.tradingview.com/tv.js"></script>
<p>Last Update: @Html.Label(DateTime.UtcNow.ToString()) - Time in UTC</p>

<div class="float-container">

    <div class="float-childsmall">
        @foreach (var watchList in Model.ViewExecutingTradesUserWatchListFollowShort)
        {
            <table id="customers">
                <caption class="text-center"><h2>@watchList.WatchListName</h2></caption>
                <caption class="text-center"><p style="font:10px;">@watchList.WatchListDescription</p></caption>
                <tr>
                    <th>Ticker</th>
                </tr>
                @foreach (var ticker in Model.ViewUserWatchListTickerModel.Where(y => y.UserWatchListId == watchList.UserWatchListId).ToList())
                {
                    <tr>
                        <td><a target="_blank" href="https://finviz.com/quote.ashx?t=@ticker.Ticker">@ticker.Ticker </a></td>
                        <!--<td>
                            @{
                                <button type="button" class="btn" id='wlButton_@watchList.WatchListName+@watchList.UserWatchListId+@ticker.Ticker'>
                                    @Html.DisplayFor(modelItem => @ticker.Ticker)
                                </button>
                            }
                        </td>-->
                        <div class="btnB" id='div_@watchList.WatchListName+@watchList.UserWatchListId+@ticker.Ticker'>
                            <p class="category-title">@ticker.Ticker</p>
                        </div>
                    </tr>
                }
            </table>
        }
    </div>
    <div class="float-child" id="researchDiv">
        <div id="htmlContainer">
            @Html.Partial("_Research", new ExecutingTrades.Models.TickerInMem() { Ticker = "META" });
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        $(".btnB").click(function () {
            $.ajax({
                url: '@Url.Action("_Research", "Dashboard")',
                type: "GET",
                data: { ticker: this.id.substring(this.id.lastIndexOf('+')) },
                cache: false,
                async: true,
                success: function (data) {
                    $("#htmlContainer").html(data);
                }
            });
        });
    })
</script>

_Research which is the partialview

@model ExecutingTrades.Models.TickerInMem
<!-- TradingView Widget BEGIN -->
<style>
    .tradingview-widget-container {
        border: 3px solid #fff;
        padding: 20px;
        height: 650px;
    }
</style>
<div class="tradingview-widget-container">

    <div class="tradingview-widget-copyright"><a href="https://www.tradingview.com/symbols/@Model.Exchange-@Model.Ticker/" rel="noopener" target="_blank"><span class="blue-text">@Model.Ticker</span></a> by TradingView</div>
    <script type="text/javascript">
        alert(@Model.Ticker);
    </script>
    <script type="text/javascript">
        new TradingView.widget(
            {
                "autosize": true,
                "symbol": "NASDAQ:@Model.Ticker",
                "interval": "D",
                "timezone": "Etc/UTC",
                "theme": "light",
                "style": "1",
                "locale": "en",
                "toolbar_bg": "#f1f3f6",
                "enable_publishing": false,
                "allow_symbol_change": true,
                "container_id": "tradingview_37810"
            }
        );
    </script>
</div>

And the Controller

public ActionResult _Research(string ticker)
    {
        if (string.IsNullOrWhiteSpace(ticker))
            return View();

        var model = new TickerInMem();
        model.Ticker = ticker.Split('+').Last();
        model.Exchange = "NASDAQ";
        return PartialView("_Research", model);
    }

When I debug - everything works, i can hit the partial view being called and the model is correct.

When the page loads: enter image description here

When clicking on a link: enter image description here

All I really want to do is load the 2nd graph which I click it to where the partial view in rendered on the view.

JL1
  • 309
  • 2
  • 18

1 Answers1

0

So my MVC and Ajax are correct, the real issue was inside of the tradingview control, I had removed the div it was referencing in the container. "container_id": "tradingview_37810"

JL1
  • 309
  • 2
  • 18