This is a migrated thread and some comments may be shown as answers.

[Solved] Passing parameter to Window content

0 Answers 179 Views
Window
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Robert
Top achievements
Rank 1
Robert asked on 19 Apr 2012, 10:53 PM

I have looked over the various demos for the Window component, but I can't find anything that completed addresses the problem I am trying to solve.

I have a grid with a custom command:

@(Html.Telerik().Grid<ACSDirect.ServiceReference.QuoteLine>()
        .Name("QuoteLine")
        .Columns(columns =>
        {
            columns.Bound(o => o.LineNumber);
            columns.Bound(e => e.SystemName);
            columns.Bound(o => o.Qty);
            columns.Bound(o => o.UnitCostList);
            columns.Bound(o => o.UnitCostCompany);
            columns.Bound(o => o.Discount_Company);
            columns.Bound(o => o.Discount_Customer);
            columns.Bound(o => o.UnitCostCustomer);
            columns.Bound(o => o.Extended_Cost_List);
            columns.Bound(o => o.Extended_Cost_Company);
            columns.Bound(o => o.Extended_Cost_Customer);
            columns.Bound(o => o.Gross_Profit);
            columns.Bound(o => o.Gross_Margin);
            columns.Command(commands =>
            {
                if (User.IsInRole("QuoteDelete"))
                    commands.Delete();
                if (User.IsInRole("QuoteUpdate"))
                    commands.Custom("addComponentBtn").Text("Add Component").DataRouteValues(route => route.Add(o => o.QuoteLineId)).Action("DialogComponentAdd", "Quote").Ajax(true);
            });
        })
        .ClientEvents(events =>
        {
            events.OnComplete("onComplete");
        })
...omitted for brevity

I have a WIndow that should open and that Window is strongly typed:

@(Html.Telerik().Window()
       .Name("ComponentAdd")
       .Title("Add Component")
       .Modal(true)
       .Visible(false)
       .Effects(effect => effect.Expand())
       .Content(@<text> @Html.Partial("_DialogComponentAdd", new QuoteBundleComponent()) </text>)
       .Width(350)
)

The partial view being rendered is an input form for the user to create a new data object:

@model XXXX.Models.QuoteBundleComponent
            
@using (Html.BeginForm("AddComponent", "Quote", FormMethod.Post, new { id = "ComponentPartForm" }))
{
...omitted for brevity

I have a controller action that passes the data route value as the response:

public JsonResult DialogComponentAdd(int id)
{
    return Json(id , JsonRequestBehavior.AllowGet);
}

And finally, the javascript to open the window:

    function onComplete(e) {
        if (e.name == "addComponentBtn") {
            $("#ComponentPartForm").attr("action", "/Quote/AddComponent/" + e.response);
            $("#ComponentAdd").data("tWindow").center().open();
        };
    };

As you can see in the javascript, I am trying to set the action of the form in the partial view the window is rendering to the response from my action method, but it is not changing the action target of the form.

Javascript ain't my thing, so clearly I am not getting something. Am I doing this the right way or is there another method of passing the form's RouteValue to it? The complication here is that the grid page and the input form are of two different types and the parameter that needs to be passed only exists on the grid row.

UPDATE:

Clearly I am a dingbat. I kept looking at the source of the page to see if the form action was changing. Of course, it wouldn't change until you actually clicked the custom button - and it works just fine.

Tags
Window
Asked by
Robert
Top achievements
Rank 1
Share this question
or