Reputation: 1347
In my code(MVC5 appilcation) I've the following code which is working when the JS file is inside the index view file,when I take the java script and put it in file inside scripts and run the program I see this '@Html.TextBox("user")' in the page,how should I adopt the code to work also from scripts that are not inside the index.
var td = $emptyRow.children().first();
td.empty();
td.append('@Html.TextBox("user")');
Upvotes: 0
Views: 70
Reputation: 10122
@Html.TextBox is the razor syntax for MVC. If you have to dynamically create text box using javascript then you should append <input />
as mentioned below:
var td = $emptyRow.children().first();
td.empty();
td.append('<input type="text" id="user"/>');
Upvotes: 3
Reputation: 15860
'@Html.TextBox("user")'
is a server-side ASP.NET helper. When you try to execute the code in Client side. It won't execute, as Client side has no assembly to handle that code.
You can however, try to connect to the Server (Ajax) to get that TextBox.
Otherwise, convert your ASP.NET code to a simle HTML element. Which would execute and create an Input field or a Textarea
Upvotes: 0