Dotnet Core button redirect with parameters











up vote
0
down vote

favorite












I'm making a Web API application that populates data into a datagrid. Currently, I'm wanting to have a button that will call my webapi endpoint with an additional parameter.



My datagrid, and the button code is below. This is the entirety of my razor page code:



@(Html.DevExtreme().DataGrid<Batch>().ID("gridContainer")
.Columns(columns =>
{
columns.Add().CellTemplate(
@<text>
@(Html.DevExtreme().Button()
.ID("sendButton")
.Text("Select Batch")
.OnClick("function () { onItemClick(data); }"))
</text>);
columns.AddFor(m => m.BatchId).Caption("BatchId");
columns.AddFor(m => m.CobId).Caption("Cob Id");
})
.DataSource(d => d.WebApi().Controller("Batches").LoadAction("GetAllEntries").Key("BatchId"))
)



<script>

var idValue;
function onItemClick(data)
{
DevExpress.ui.notify(data.Id);
console.log(data.BatchId);

idValue = data.BatchId;

window.location.href = '@Url.Action("SeanTest", "BatchDatagrid", new {@id = idValue })';
}

</script>


In my script the variable idValue contains the value I want to pass into my URL, yet when I try to place it in the Url.Action it tells me that it doesn't exist in the current context



What is the best way to pass idValue into my redirect action?










share|improve this question
























  • Possible duplicate of how to pass parameter from @Url.Action to controller function in asp.net mvc3
    – Kirk Larkin
    Nov 7 at 11:50















up vote
0
down vote

favorite












I'm making a Web API application that populates data into a datagrid. Currently, I'm wanting to have a button that will call my webapi endpoint with an additional parameter.



My datagrid, and the button code is below. This is the entirety of my razor page code:



@(Html.DevExtreme().DataGrid<Batch>().ID("gridContainer")
.Columns(columns =>
{
columns.Add().CellTemplate(
@<text>
@(Html.DevExtreme().Button()
.ID("sendButton")
.Text("Select Batch")
.OnClick("function () { onItemClick(data); }"))
</text>);
columns.AddFor(m => m.BatchId).Caption("BatchId");
columns.AddFor(m => m.CobId).Caption("Cob Id");
})
.DataSource(d => d.WebApi().Controller("Batches").LoadAction("GetAllEntries").Key("BatchId"))
)



<script>

var idValue;
function onItemClick(data)
{
DevExpress.ui.notify(data.Id);
console.log(data.BatchId);

idValue = data.BatchId;

window.location.href = '@Url.Action("SeanTest", "BatchDatagrid", new {@id = idValue })';
}

</script>


In my script the variable idValue contains the value I want to pass into my URL, yet when I try to place it in the Url.Action it tells me that it doesn't exist in the current context



What is the best way to pass idValue into my redirect action?










share|improve this question
























  • Possible duplicate of how to pass parameter from @Url.Action to controller function in asp.net mvc3
    – Kirk Larkin
    Nov 7 at 11:50













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm making a Web API application that populates data into a datagrid. Currently, I'm wanting to have a button that will call my webapi endpoint with an additional parameter.



My datagrid, and the button code is below. This is the entirety of my razor page code:



@(Html.DevExtreme().DataGrid<Batch>().ID("gridContainer")
.Columns(columns =>
{
columns.Add().CellTemplate(
@<text>
@(Html.DevExtreme().Button()
.ID("sendButton")
.Text("Select Batch")
.OnClick("function () { onItemClick(data); }"))
</text>);
columns.AddFor(m => m.BatchId).Caption("BatchId");
columns.AddFor(m => m.CobId).Caption("Cob Id");
})
.DataSource(d => d.WebApi().Controller("Batches").LoadAction("GetAllEntries").Key("BatchId"))
)



<script>

var idValue;
function onItemClick(data)
{
DevExpress.ui.notify(data.Id);
console.log(data.BatchId);

idValue = data.BatchId;

window.location.href = '@Url.Action("SeanTest", "BatchDatagrid", new {@id = idValue })';
}

</script>


In my script the variable idValue contains the value I want to pass into my URL, yet when I try to place it in the Url.Action it tells me that it doesn't exist in the current context



What is the best way to pass idValue into my redirect action?










share|improve this question















I'm making a Web API application that populates data into a datagrid. Currently, I'm wanting to have a button that will call my webapi endpoint with an additional parameter.



My datagrid, and the button code is below. This is the entirety of my razor page code:



@(Html.DevExtreme().DataGrid<Batch>().ID("gridContainer")
.Columns(columns =>
{
columns.Add().CellTemplate(
@<text>
@(Html.DevExtreme().Button()
.ID("sendButton")
.Text("Select Batch")
.OnClick("function () { onItemClick(data); }"))
</text>);
columns.AddFor(m => m.BatchId).Caption("BatchId");
columns.AddFor(m => m.CobId).Caption("Cob Id");
})
.DataSource(d => d.WebApi().Controller("Batches").LoadAction("GetAllEntries").Key("BatchId"))
)



<script>

var idValue;
function onItemClick(data)
{
DevExpress.ui.notify(data.Id);
console.log(data.BatchId);

idValue = data.BatchId;

window.location.href = '@Url.Action("SeanTest", "BatchDatagrid", new {@id = idValue })';
}

</script>


In my script the variable idValue contains the value I want to pass into my URL, yet when I try to place it in the Url.Action it tells me that it doesn't exist in the current context



What is the best way to pass idValue into my redirect action?







javascript c# .net-core






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 11:34

























asked Nov 7 at 11:14









N0xus

1,295742100




1,295742100












  • Possible duplicate of how to pass parameter from @Url.Action to controller function in asp.net mvc3
    – Kirk Larkin
    Nov 7 at 11:50


















  • Possible duplicate of how to pass parameter from @Url.Action to controller function in asp.net mvc3
    – Kirk Larkin
    Nov 7 at 11:50
















Possible duplicate of how to pass parameter from @Url.Action to controller function in asp.net mvc3
– Kirk Larkin
Nov 7 at 11:50




Possible duplicate of how to pass parameter from @Url.Action to controller function in asp.net mvc3
– Kirk Larkin
Nov 7 at 11:50












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










The @Url.Action is processed at the server side. So passing a dynamic value from client side to it may not be possible. But as a work-around you can use the below code



window.location.href = '@Url.Action("SeanTest", "BatchDatagrid", new {@id = "ID"})'.replace("ID",idValue );


If you like it, credit should be given to the original poster here






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53188380%2fdotnet-core-button-redirect-with-parameters%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    The @Url.Action is processed at the server side. So passing a dynamic value from client side to it may not be possible. But as a work-around you can use the below code



    window.location.href = '@Url.Action("SeanTest", "BatchDatagrid", new {@id = "ID"})'.replace("ID",idValue );


    If you like it, credit should be given to the original poster here






    share|improve this answer

























      up vote
      1
      down vote



      accepted










      The @Url.Action is processed at the server side. So passing a dynamic value from client side to it may not be possible. But as a work-around you can use the below code



      window.location.href = '@Url.Action("SeanTest", "BatchDatagrid", new {@id = "ID"})'.replace("ID",idValue );


      If you like it, credit should be given to the original poster here






      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        The @Url.Action is processed at the server side. So passing a dynamic value from client side to it may not be possible. But as a work-around you can use the below code



        window.location.href = '@Url.Action("SeanTest", "BatchDatagrid", new {@id = "ID"})'.replace("ID",idValue );


        If you like it, credit should be given to the original poster here






        share|improve this answer












        The @Url.Action is processed at the server side. So passing a dynamic value from client side to it may not be possible. But as a work-around you can use the below code



        window.location.href = '@Url.Action("SeanTest", "BatchDatagrid", new {@id = "ID"})'.replace("ID",idValue );


        If you like it, credit should be given to the original poster here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 7 at 11:47









        Thangadurai

        1,165923




        1,165923






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53188380%2fdotnet-core-button-redirect-with-parameters%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()