Kendo Window - LoadDataFrom finds argument value inline?

1.4k Views Asked by At

I have a kendo window which I want to populate depending on a selection made in a dropdown. I've tried refreshing the window upon open, but I can't figure out how to make that work. Changing gears, I'm wondering if I can instead send a variable parameter to the controller within window declaration itself, and then do a simple window.refresh (instead of coding the refresh to hit a specific controller, which isn't working).

I mean something like this:

@(Html.Kendo().Window()
    .Name("EditWindow")
    .Title("Edit Contact")
    .LoadContentFrom("_ContactEdit", "Contacts", new { selectedContact = $("#ContactId").data("kendoComboBox").value() })
    .Content("Loading...")
    .Visible(false)
    .Draggable()
    .Resizable()
    .Width(400)
    .Modal(true)
    .Actions(actions => actions.Pin().Minimize().Maximize().Close())
)

Or this:

@(Html.Kendo().Window()
    .Name("EditWindow")
    .Title("Edit Contact")
    .LoadContentFrom("_ContactEdit", "Contacts", new { selectedContact = getContact() })
    .Content("Loading...")
    .Visible(false)
    .Draggable()
    .Resizable()
    .Width(400)
    .Modal(true)
    .Actions(actions => actions.Pin().Minimize().Maximize().Close())
)

Obviously neither of these work, but I'm wondering if there's another way to fill in this field?

Thank you!

edit: Adding relevant code from controller and window/partial view. My controller is now being hit, but my window is not pulling the correct data. Any ideas?

Window:

@model [taking out company info].Contact
@using Kendo.Mvc.Extensions

@using (Html.BeginForm())
{

@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset id="infoForm">Hello, world.
    @Html.HiddenFor(model => model.ContactId, new { id = "EditWindowId" })
        <br />
        <label id ="ContactNameID" style="width: 130px;">Contact Name</label>
        <span>
            @Html.TextBoxFor(model => model.FullName, new { type = "text", id = "EditWindowName", @class = "k-textbox form-control", style = "width: 200px; cursor:default" })
        </span><br />
    </fieldset>
}

Controller:

    [HttpGet]
    public ActionResult _ContactEdit(int selectedContact)
    {
        var entities = from r in dbContext.Contacts
                       where r.ContactId == selectedContact
                       select r;
        if (entities.Any())
        { return PartialView(entities.First()); }
        else
        { return HttpNotFound("Contact does not exist."); }
    }
1

There are 1 best solutions below

2
On

You can leverage the change event of your dropdown list to grab the selected value. Once you have the selected value you can programmatically refresh the window with the appropriate action on your controller. For example, the code below defines a Kendo DropDownList with a subscription to the change event. In the change, the value is used to build a dynamic url, and the kendo window is refreshed with that url:

<%= Html.Kendo().DropDownList()
        .Name("dropdownlist")
        ...
        .Events(e =>
        {
            e.Change("onChange")
        })
%>

<script type='text/javascript'>
    function onChange(){
        var value = this.value(),
            window = $("#EditWindow").data("kendoWindow");

        window.refresh({
           url: "/Contact/_ContactEdit?selectedContact=" + value 
        });
    }
</script>