The below code generated from C# string builder and attached to data table. I am trying put window.location in single quote but it is generated like above post.
Your approach will not work as Razor code runs on the server. I assume the StringBuilder is in an action method. You'll need to hard code the URL or use data driven design.
For the second time, if you want help you'll need to post all the relevant code.
Member
140 Points
305 Posts
window.location not genareted correctly in browser
Mar 09, 2018 01:15 PM|venkimca|LINK
Hi,
I have some issue while generating url from C# code. My javascript function is prepared from C# code. So I have given like below
window.location.herf='@Url.Ation(""Index"",""Signoff"")'; but it is generated in browser like -->http://localhost:9988/@Url.Action(%22Index%%22,%22Signoff%22) ,So I have given like below
window.location.herf='Signoff/Index';
Worked : If my current url is http://localhost:9988/ControlName then it is generated -->http://localhost:9988/Signoff/Index
Not Worked: If my current url is http://localhost:9988/ControlName/ActionName then it is generated --> http://localhost:9988/ControllerName/Signoff/Index
If any points on above issue.
Thanks in advance ,
Venkat
All-Star
52101 Points
23231 Posts
Re: window.location not genareted correctly in browser
Mar 09, 2018 01:38 PM|mgebhard|LINK
The Razor and JavaScript has syntax errors.
If you are still having issues after fixing the typos, then post all the relevant code. That will help us to help you.
Member
140 Points
305 Posts
Re: window.location not genareted correctly in browser
Mar 09, 2018 01:48 PM|venkimca|LINK
Thanks for your reply,
The below code generated from C# string builder and attached to data table. I am trying put window.location in single quote but it is generated like above post.
StringBuilder Script='$.ajax({
type: "get", url: "/SomeController/ActionMethod1",
data: { accountNumber: accountNumber }, dataType: 'json',
success: function(response)
{ if (response == null)
{ window.location.href = '@Url.Action(""Signoff"")'; }
else { $(target).html(response); } },
error:function(response){$(target).html('An error occured'); }});';
All-Star
52101 Points
23231 Posts
Re: window.location not genareted correctly in browser
Mar 09, 2018 01:54 PM|mgebhard|LINK
Your approach will not work as Razor code runs on the server. I assume the StringBuilder is in an action method. You'll need to hard code the URL or use data driven design.
For the second time, if you want help you'll need to post all the relevant code.