How can a partial view on the create view that has to e 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.
/
How can a partial view on the create view that has to e 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./dotnet/asp-net/tips-and-tricks-about-razor-partial-views/
Share Improve this question edited May 23, 2017 at 11:46 CommunityBot 11 silver badge asked Jan 27, 2017 at 22:37 user7480455user7480455 10-
1
You need to use ajax to dynamically update the view (exactly as both the links you have included show). And the error is obvious - your have not created a view
UpdateIssuesList.cshtml
– user3559349 Commented Jan 27, 2017 at 22:41 -
1
If your view is named
_IssuesListPartial.cshtml
, then it needs to bereturn View("_IssuesListPartial");
– user3559349 Commented Jan 30, 2017 at 21:13 -
1
Of course it can be done! The error means you have not created a view with the name
UpdateIssuesList.cshtml
– user3559349 Commented Jan 30, 2017 at 21:27 - 2 A partial view is a view (it just does not have a layout)! And in order to respond to client side events (e.g. selecting an option from a dropdownlist), you need javascript, and to update the DOM, you need ajax to call a server method which returns a partial view – user3559349 Commented Jan 30, 2017 at 21:57
- 1 Hi @007, You should create a dropdown list (DropDownListFor) instead of a table, with the values ing from your IssueList (ing from your controller/name_view. HttpGet). In it onclick event you must to call it wrapped form, controller/name_view (HttpPost). You will return back the model and a control´s ViewBag which will render your partial view or not (with value ing from the model and return back from the controller). This partial must to have another method (controller/name_partialview), which, in function of the model you are passing to it (RenderAction), let you render your partial – Kenzo_Gilead Commented Feb 1, 2017 at 10:36
2 Answers
Reset to default 4I 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();
}
});
Is that enough?
$("#PV_IssueList").load("/controllerx/UpdateIssuesList?VID=1");
When you need refresh, call this jquery line... or put it inside a function, or any event.. for example onclick='$("#PV_IssueList").load("/controllerx/UpdateIssuesList?VID=1");'