0

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

  • 1
    _since mvc is for phones small devices_ is totally incorrect. –  Jan 30 '17 at 23:04
  • 1
    Not really clear what your wanting to display, but if you want to update the html in the `
    ` element, then it needs to be `$.get('/Create/_IssuesListPartial', { VID: 1 }, function(data) { $('#PV_IssueList').html(data); });`
    –  Jan 30 '17 at 23:14
  • 1
    And if your wanting to send the value of the element with `id="RES_ID"`, then replace `{ VID: 1 }` with `{ VID: $(this).val() }` –  Jan 30 '17 at 23:15
  • 1
    Your question is not clear. If you want to create a partial display based on a dropdown selection it is fairly easy. Please explain what you want. I don't understand what `$.post("/Create/_IssuesListPartial?VID=1")` will do – progrAmmar Jan 31 '17 at 07:53
  • @progrAmmar hi what I am trying to do is populate a partial view with a list.The list gets populated when the the drop down lists value changes the list gets changed. That value is sent to the the function that makes the list and then that list gets pushed to the create view screen via the the partial view On change on the drop down list. And if the list returns no value I want the list to disappear. I don't think mvc can do this because I have never seen it done and based on other questions asked. It appears that no one been able to make it work. I guess phones can handle that complexity. Tks –  Jan 31 '17 at 15:42
  • @progrAmmar said "I don't understand what $.post("/Create/_IssuesListPartial?VID=1") will do – progrAmmar" I don't either... Some one said try that in another thread so I did. I have no idea how any of this works. It seem like a nice feature to add to the application but I am finding that mvc can't do all the neat things you can do in webforms... and there appears to be huge limitations in mvc based on my findings. But this app needed to work on a mobile device so mvc was selected. But it appears to be a poor choice since it can't so some basic UI operations. –  Jan 31 '17 at 15:44

1 Answers1

0

Ok for some reason the answer was deleted so I will try to answer it differently. The way I got this to work was first with the help of user on this form and other forms as well along with some research. Using the ajax language was a big help as suggested.

Here is the Ajax code behind:

$(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();
                }
            });

So to break down whats going on here is that I have in my controller a function called UpdatePartialViewList this function passes back a partial view along with its view bag:

The Function in the controller is this:

[HttpGet]
public ActionResult UpdatePartialViewList(int? VID)
{           

    ViewBag.AList = Get_List(VID);
    return PartialView("_WidgetListPartial",ViewBag.AList);


}

So with these two items you have like a place holder it seems. because this will pass the information back to the page. So in my create view I have this:

UpdatePartialViewList(int.Parse(Collection["RES_VID"])); On Your Create View Screen where you want your partial view to display

    <div class="col-sm-6">

        <div class="form-horizontal" style="display:none" id="PV_WidgetList">

            @{ Html.RenderAction("UpdatePartialViewList");}



        </div>
    </div>

Hopefully this help other that are use to webforms and are trying to get the whole mvc thing. Best wishes!