Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
119
rated 0 times [  126] [ 7]  / answers: 1 / hits: 15209  / 7 Years ago, fri, january 27, 2017, 12:00:00

How can a partial view on the create view that has to come in empty be refreshed with new data when a user selects a value from a list a values drop down?



I have a tried a bunch of stuff listed on the message board as well as others and it just drills down to more errors. I just can't believe something so easy in webforms is this hard to do in MVC.



I tried this both in Chrome and IE and get errors so I'm lost. I have something like this for a partial view in the shared folder:



<table cellpadding=1 border=1>
.... // table header
@foreach (SYSTEMX.Models.VUE_ISSUE_LIST item in ViewBag.IssuesList)
{
<tr>
<td>@item.Issue</td>
</tr>
}
</table>


The Create cshtml file has this:



<div class=col-sm-6>
<div class=form-horizontal style=display:none id=PV_IssueList>
@{ Html.RenderAction(UpdateIssuesList); }
</div>
</div>


In the Controller there is code similar to this



[HttpGet]
public ActionResult UpdateIssuesList(int? VID)
{
ViewBag.IssuesList = GetIssuesList(VID);
return PartialView(UpdateIssuesList);
}


The GetIssuesList(VID) looks very similar to this and it is in the controller of the mvc application



private List<VUE_ISSUE_LIST> GetIssuesList(int? VID)
{
return db.VUE_ISSUE_LIST_.Where(i => i.ID == VID).ToList();
}


I get this error. I'm clueless to what is going on here.




The partial view 'UpdateIssuesList' was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/CONTROLLERX/UpdateIssuesList.aspx

~/Views/CONTROLLERX/UpdateIssuesList.ascx

~/Views/Shared/UpdateIssuesList.aspx

~/Views/Shared/UpdateIssuesList.ascx

~/Views/CONTROLLERX/UpdateIssuesList.cshtml

~/Views/CONTROLLERX/UpdateIssuesList.vbhtml

~/Views/Shared/UpdateIssuesList.cshtml

~/Views/Shared/UpdateIssuesList.vbhtml




A forum user posted something like this as a solution and I guess it worked for him as he put a green check mark but it does not work for me at all:



Updating PartialView mvc 4



Also tried this:



refresh a partial view in mvc



Also read over this but it is so very technical that I don't follow it all that well.



https://www.simple-talk.com/dotnet/asp-net/tips-and-tricks-about-razor-partial-views/


More From » asp.net-mvc

 Answers
67

I ended up using some called Ajax in the code behind that reads the click from the dropdown list. get the value of the selected item and passed the values back to



all of the controller code behind to build the list and send it to update the partial view and if there is data there it pass the partial view



with the update list to the create form.



    $(document).ready(function () {
$('#RES_VID').change(function ()
{

debugger;

$.ajax(

{
url: '@Url.Action(UpdatePartialViewList)',
type: 'GET',
data: { VID: $('#RES_VID').val() },

success: function (partialView)
{
$('#PV_WidgetList').html(partialView);
$('#PV_WidgetList').show();
}
});

[#59178] Wednesday, January 25, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eanskylerg

Total Points: 524
Total Questions: 107
Total Answers: 100

Location: Colombia
Member since Mon, May 2, 2022
2 Years ago
;