0

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")');

2 Answers 2

3

@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"/>');
Sign up to request clarification or add additional context in comments.

Comments

0
'@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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.