简体   繁体   中英

Accessing my Object properties from javascript and Using MVC razor Url.Action

I am mixing Javascript and Razor code to redirect to a page sending a couple params.Heres my code that I tried.

function insertSuccess(data) {
       $('#NewCategoryGroup').dialog('close');
       var  myId = data.Object.GroupCatId;
       var  myName = data.Object.ItemCategoryGroup;
        window.location.replace("@Url.Action("CatGroupDetails","TaxRules",new { id = myId, name = myName })");
    }

I can replace Id = 1 and name = "test" and it works. But when I try to use variables it wont let me. Do I have to write my URL the old way -- "http://www.someweb.com/5?Name=test". Thanks for the help.

I think in your code above myId and myName are javascript variables, but you are trying to use them under the C-Sharp scope. Url.Action is a C# function here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM