Update @Html.Partial() View only

248 Views Asked by At

I am not looking for a javascript/jquery answer. I can do that, but I feel like it breaks the purpose. This seems like something that should be possible without javascript.

I'm trying to get a simple listbox selection to update an @Html.Partial section, and I'm not exactly sure what to do. Everything loads initially just fine. After I submit, however, I am not quite sure how to 'attach' to my partial view to update it.

The purpose here is to only load the listbox one time, and let them view or request as many new reports as they want without reloading. If it's not possible, that's fine, I can use one page, reload the listboxes, and it will work. I just don't see why I would need to go to the database to reload the listbox items every time they view or request a report.

"master" html page:

@using TCTReports.Models
@model ReportViewModel
<h2>My Reports</h2>
<div class="row">
<div class="col-md-6">
    <h3>Select Report</h3>
    @using (Html.BeginForm("GetReport", "Report"))
    {
        @Html.DropDownListFor(m => m.SelectedMyID, Model.myLB)
       <input type="submit" value="View" />
    }      
</div>
<div class="col-md-6">
    <h3>All Reports</h3>
    @using (Html.BeginForm("ReqReport", "Report"))
    {
        @Html.DropDownListFor(m => m.SelectedAllID, Model.allLB)
        <input type="submit" value="View" />
    }
</div>
</div>
@Html.Partial("_Msg")

_Msg is super simple atm. It would eventually be a report viewer, for now, it looks at @Viewbag...

<h2>@ViewBag.Message</h2>

Controller submit actions (I get my selected value just fine. currently on void but was ActionResult with Views - but I don't feel like that is correct either, as it completely overwrites the page (even with PartialView) and I lose my listboxes and _layout...):

public void GetReport(ReportViewModel model)
    {
        var myID = model.SelectedMyID;            
        ViewBag.Message = "Report: " + myID.ToString() + " Selected.";
        //return PartialView("_Msg","Test");
    }
    public void ReqReport(ReportViewModel model)
    {
        var allID = model.SelectedAllID;
        ViewBag.Message = "Report: " + allID.ToString() + " Requested.";
        //return PartialView("_Msg", "Test");
    }

Ok, so how would I go about updating _Msg and refreshing only the @Html.PartialView() section of my master html page? I played with @sections briefly but didn't make much progress.

0

There are 0 best solutions below