Domanda

I am generating the view layout based on the screen resolution using javascript, all DIV and tables work well except the Html.ActionLink. Converting:

@(Html.ActionLink("Back", "index", "home", new{loggedIn = ViewBag.id}, new {@class = "t-button", @style = "width: 200px; color: white; text-align: center" }))

using:

document.write("@(Html.ActionLink(\"Back\", \"index\", \"home\", new");
document.write("{");
document.write("loggedIn = ViewBag.id");
document.write("}, new");
document.write("{");
document.write("@class = \"t-button\",");
document.write("@style = \"width: 200px; color: white; text-align: center\"");
document.write("}))");

Did not work, I get this error:

The explicit expression block is missing a closing ")" character.

Tried to add ")" at the end but did not work; would appreciate your suggestions.

È stato utile?

Soluzione

Razor code is server side and is sent to the client already rendered. Getting the client to write Razor code in javascript will not work.

Instead, you can just write your <a></a> tag directly. You can use some server side variables though using razor. For example:

document.write('<a class="t-button" style="width: 200px; color: white; text-align: center" href="index/home?loggedin=@ViewBag.id" >Back</a>');

That way you can pick up your server side values and create the link as you require it.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top