The option I am trying to apply to a create view form is one on which the user selects an item from the drop down list on a create from before a record is written to the database and as they select their records from the dropdown list on the create view form a partial view that is hidden on this form becomes visible and shows values that are in a viewbag.
As I have seeked help for this before I don't this the question was clear on what the goal was and that this is on the create which may prevent from happening as this may be a limitation within the mvc methods since mvc is for phones small devices. I am building this application on a full pc. Some say it can be done. I am using viewbag as that is the only thing I understand.. I don't understand the model concept and I don't know what ajax is or how to use. I just know how to do the javascripting functions as I have seen examples w3schools.
What I have so far,
I have something similar to this for my partial view: Called _IssuesListPartial
<table cellpadding="1" border="1">
<tr>
<th>
Issues List
</th>
</tr>
@foreach (SystemX.Models.VUE_ISSUE_LIST_FULL item in ViewBag.IssuesList)
{
<tr>
<td>
@item.ISSUE_DISCRIPTION
</td>
</tr>
}
</table>
In my crated Controller code behind I have under the create option a few items I have a function that makes a list for the view bag.
private List<VUE_ISSUE_LIST_FULL> Get_IssuesList(int? VID)
{
return db.VUE_ISSUE_LIST_FULL.Where(i => i.ID == VID).ToList();
}
I then assign the results to the view bag in another function that starts with the words action results. Its called UpdateIssuesList:
This is under the create logic in the controller.I saw something similar they had a [HttpPost] but I get an error when the create form is trying to render so I changed it to [HttpGet] it works and the create for loads. I am not sure that the [HttpGet] or [HttpPost] does..I just know that the create forms loads with [HttpGet]
So in the controller under the create functions I have this. Please keep in mind I have all of the other stuff that the scaffold builder made for the create view. I just added this code behind under it.
[HttpGet]
public ActionResult UpdateIssuesList(int? VID)
{
ViewBag.IssuesList = Get_IssuesList(VID);
return PartialView("_IssuesListPartial",ViewBag.IssuesList);
}
In the create form view I have as few items... The area on the form where I would like this list to show when it is made visible:
under function public ActionResult Create I have:
public ActionResult Create(int RES_ID, FormCollection Collection, [Bind(Include = "R.... and so on...
UpdateIssuesList(int.Parse(Collection["RES_ID"]));
and under the public ActionResult Create()I have: the function call to the UpdateIssuesList funtion.. I just send a random value that will build a blank list.
UpdateIssuesList(808);
Also
This is the code behind for the create view form where I want to render the partial view:
<div class="col-sm-6">
<div class="form-horizontal" style="display:none" id="PV_IssueList">
@{ Html.RenderAction("UpdateIssuesList",new {@VID = 1 });}
</div>
</div>
And I also have in the script section of the create view form the code behind that run when the user makes a change to the drop down list on the create view form. The end goal again is when the user click and changes the item on the dropdown list... the value gets id values gets sent to the list maker and and generates a new last and that new list is passed to the partial view and the form is updated.
$(document).ready(function () {
$('#RES_ID').change(function ()
{
debugger;
$("#PV_IssueList").show(); // Shows List
$.post("/Create/_IssuesListPartial?VID=1")
});
})
is it possible for mvc to update a create from as there is nothing there ? No code or event trigger that will refreshes the partial view before the form is submitted So This may not be possible with mvc and I am wasting my time trying. I have just smashed together peoples Ideas that I have seen as I have not seen an actual example of a list being rendered in the create view so I way be chasing windmills here. Thanks for taking time to read this.
So when I run this code I get on the page after I selected a value the head text of the partial view but on list data. When I step through I get data in the variables and stuff but not on screen in the create view form