How to add a javascript variable inside a razor list
up vote
-1
down vote
favorite
Hi all I'm really confused in adding a var parameter inside a razor object and the answers I found didn't resolve my issue. How do I correctly do this. I'm new to Razor binding
Here's my script
<script>
$(document).ready(function () {
function addRow(){
var id = 1;
var html= '<tr>' +
'<td><input id="TxtExtent1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_EXTENT_CONFIDENCE_EN"></td>' +
'<td><input id="TxtRanks1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_RANK_EN"></td>' +
'<td><input id="TxtCategory1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_CATEGORY_EN"></td>' +
'<td><input id="TxtStandardgrades1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_STD_GRADES"></td>' +
'<td><input id="TxtTotalweight1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_TOTAL_WEIGHTED_SCORE"></td>' +
'<td><input id="TxtIQscores1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_IQ_SCORES_EN"></td>' +
'<td><input type="button" class="BtnPlus" value="+" /></td>' +
'<td><input type="button" class="BtnMinus" value="-" /></td>' +
+'<tr>'
$(html).appendTo($("#TableExtent"))
id++;
};
$("#TableExtent").on("click", ".BtnPlus", addRow);
});
</script>
As you can see How do I add this var id
inside the FORM_7_LIST[0].F7_EXTENT_CONFIDENCE_EN
. help would be appreciated.
javascript c# html razor data-binding
add a comment |
up vote
-1
down vote
favorite
Hi all I'm really confused in adding a var parameter inside a razor object and the answers I found didn't resolve my issue. How do I correctly do this. I'm new to Razor binding
Here's my script
<script>
$(document).ready(function () {
function addRow(){
var id = 1;
var html= '<tr>' +
'<td><input id="TxtExtent1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_EXTENT_CONFIDENCE_EN"></td>' +
'<td><input id="TxtRanks1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_RANK_EN"></td>' +
'<td><input id="TxtCategory1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_CATEGORY_EN"></td>' +
'<td><input id="TxtStandardgrades1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_STD_GRADES"></td>' +
'<td><input id="TxtTotalweight1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_TOTAL_WEIGHTED_SCORE"></td>' +
'<td><input id="TxtIQscores1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_IQ_SCORES_EN"></td>' +
'<td><input type="button" class="BtnPlus" value="+" /></td>' +
'<td><input type="button" class="BtnMinus" value="-" /></td>' +
+'<tr>'
$(html).appendTo($("#TableExtent"))
id++;
};
$("#TableExtent").on("click", ".BtnPlus", addRow);
});
</script>
As you can see How do I add this var id
inside the FORM_7_LIST[0].F7_EXTENT_CONFIDENCE_EN
. help would be appreciated.
javascript c# html razor data-binding
Razor runs on the server, Javascript runs on the client. So the simple answer is: you cannot, and you shouldn't have to. Even more, you shouldn't be concatenating strings to create HTML.
– Camilo Terevinto
Nov 8 at 11:46
@CamiloTerevinto Then How do I dynamically resolve this issue? Here I have tried to add more textfield by addRow function.
– Ashane Alvis
Nov 8 at 11:47
1
You don't, and you don't have to. Create the entire structure using Razor and give the client the last index used:var lastIndex = @i;
. Even more, that won't work as you would expect once in the client, the constants will work, but the indexers not.
– Camilo Terevinto
Nov 8 at 11:48
Can you give me an example? On how to convert this?
– Ashane Alvis
Nov 8 at 11:50
I would do this: 1. Remove that HTML concatenation. 2. create a Partial View with that structure. 3. Create an Action method so you can call it from the client. 4. use AJAX to get that HTML from the server and then append it to#TableExtent
as you are already doing.
– Camilo Terevinto
Nov 8 at 11:51
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
Hi all I'm really confused in adding a var parameter inside a razor object and the answers I found didn't resolve my issue. How do I correctly do this. I'm new to Razor binding
Here's my script
<script>
$(document).ready(function () {
function addRow(){
var id = 1;
var html= '<tr>' +
'<td><input id="TxtExtent1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_EXTENT_CONFIDENCE_EN"></td>' +
'<td><input id="TxtRanks1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_RANK_EN"></td>' +
'<td><input id="TxtCategory1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_CATEGORY_EN"></td>' +
'<td><input id="TxtStandardgrades1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_STD_GRADES"></td>' +
'<td><input id="TxtTotalweight1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_TOTAL_WEIGHTED_SCORE"></td>' +
'<td><input id="TxtIQscores1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_IQ_SCORES_EN"></td>' +
'<td><input type="button" class="BtnPlus" value="+" /></td>' +
'<td><input type="button" class="BtnMinus" value="-" /></td>' +
+'<tr>'
$(html).appendTo($("#TableExtent"))
id++;
};
$("#TableExtent").on("click", ".BtnPlus", addRow);
});
</script>
As you can see How do I add this var id
inside the FORM_7_LIST[0].F7_EXTENT_CONFIDENCE_EN
. help would be appreciated.
javascript c# html razor data-binding
Hi all I'm really confused in adding a var parameter inside a razor object and the answers I found didn't resolve my issue. How do I correctly do this. I'm new to Razor binding
Here's my script
<script>
$(document).ready(function () {
function addRow(){
var id = 1;
var html= '<tr>' +
'<td><input id="TxtExtent1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_EXTENT_CONFIDENCE_EN"></td>' +
'<td><input id="TxtRanks1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_RANK_EN"></td>' +
'<td><input id="TxtCategory1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_CATEGORY_EN"></td>' +
'<td><input id="TxtStandardgrades1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_STD_GRADES"></td>' +
'<td><input id="TxtTotalweight1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_TOTAL_WEIGHTED_SCORE"></td>' +
'<td><input id="TxtIQscores1" type="text" class="form-control" placeholder="@ResGlobal.ENTER" value="@Model.TabFormViewModel.FORM_7_LIST[0].F7_IQ_SCORES_EN"></td>' +
'<td><input type="button" class="BtnPlus" value="+" /></td>' +
'<td><input type="button" class="BtnMinus" value="-" /></td>' +
+'<tr>'
$(html).appendTo($("#TableExtent"))
id++;
};
$("#TableExtent").on("click", ".BtnPlus", addRow);
});
</script>
As you can see How do I add this var id
inside the FORM_7_LIST[0].F7_EXTENT_CONFIDENCE_EN
. help would be appreciated.
javascript c# html razor data-binding
javascript c# html razor data-binding
asked Nov 8 at 11:40
Ashane Alvis
40111026
40111026
Razor runs on the server, Javascript runs on the client. So the simple answer is: you cannot, and you shouldn't have to. Even more, you shouldn't be concatenating strings to create HTML.
– Camilo Terevinto
Nov 8 at 11:46
@CamiloTerevinto Then How do I dynamically resolve this issue? Here I have tried to add more textfield by addRow function.
– Ashane Alvis
Nov 8 at 11:47
1
You don't, and you don't have to. Create the entire structure using Razor and give the client the last index used:var lastIndex = @i;
. Even more, that won't work as you would expect once in the client, the constants will work, but the indexers not.
– Camilo Terevinto
Nov 8 at 11:48
Can you give me an example? On how to convert this?
– Ashane Alvis
Nov 8 at 11:50
I would do this: 1. Remove that HTML concatenation. 2. create a Partial View with that structure. 3. Create an Action method so you can call it from the client. 4. use AJAX to get that HTML from the server and then append it to#TableExtent
as you are already doing.
– Camilo Terevinto
Nov 8 at 11:51
add a comment |
Razor runs on the server, Javascript runs on the client. So the simple answer is: you cannot, and you shouldn't have to. Even more, you shouldn't be concatenating strings to create HTML.
– Camilo Terevinto
Nov 8 at 11:46
@CamiloTerevinto Then How do I dynamically resolve this issue? Here I have tried to add more textfield by addRow function.
– Ashane Alvis
Nov 8 at 11:47
1
You don't, and you don't have to. Create the entire structure using Razor and give the client the last index used:var lastIndex = @i;
. Even more, that won't work as you would expect once in the client, the constants will work, but the indexers not.
– Camilo Terevinto
Nov 8 at 11:48
Can you give me an example? On how to convert this?
– Ashane Alvis
Nov 8 at 11:50
I would do this: 1. Remove that HTML concatenation. 2. create a Partial View with that structure. 3. Create an Action method so you can call it from the client. 4. use AJAX to get that HTML from the server and then append it to#TableExtent
as you are already doing.
– Camilo Terevinto
Nov 8 at 11:51
Razor runs on the server, Javascript runs on the client. So the simple answer is: you cannot, and you shouldn't have to. Even more, you shouldn't be concatenating strings to create HTML.
– Camilo Terevinto
Nov 8 at 11:46
Razor runs on the server, Javascript runs on the client. So the simple answer is: you cannot, and you shouldn't have to. Even more, you shouldn't be concatenating strings to create HTML.
– Camilo Terevinto
Nov 8 at 11:46
@CamiloTerevinto Then How do I dynamically resolve this issue? Here I have tried to add more textfield by addRow function.
– Ashane Alvis
Nov 8 at 11:47
@CamiloTerevinto Then How do I dynamically resolve this issue? Here I have tried to add more textfield by addRow function.
– Ashane Alvis
Nov 8 at 11:47
1
1
You don't, and you don't have to. Create the entire structure using Razor and give the client the last index used:
var lastIndex = @i;
. Even more, that won't work as you would expect once in the client, the constants will work, but the indexers not.– Camilo Terevinto
Nov 8 at 11:48
You don't, and you don't have to. Create the entire structure using Razor and give the client the last index used:
var lastIndex = @i;
. Even more, that won't work as you would expect once in the client, the constants will work, but the indexers not.– Camilo Terevinto
Nov 8 at 11:48
Can you give me an example? On how to convert this?
– Ashane Alvis
Nov 8 at 11:50
Can you give me an example? On how to convert this?
– Ashane Alvis
Nov 8 at 11:50
I would do this: 1. Remove that HTML concatenation. 2. create a Partial View with that structure. 3. Create an Action method so you can call it from the client. 4. use AJAX to get that HTML from the server and then append it to
#TableExtent
as you are already doing.– Camilo Terevinto
Nov 8 at 11:51
I would do this: 1. Remove that HTML concatenation. 2. create a Partial View with that structure. 3. Create an Action method so you can call it from the client. 4. use AJAX to get that HTML from the server and then append it to
#TableExtent
as you are already doing.– Camilo Terevinto
Nov 8 at 11:51
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53207013%2fhow-to-add-a-javascript-variable-inside-a-razor-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Razor runs on the server, Javascript runs on the client. So the simple answer is: you cannot, and you shouldn't have to. Even more, you shouldn't be concatenating strings to create HTML.
– Camilo Terevinto
Nov 8 at 11:46
@CamiloTerevinto Then How do I dynamically resolve this issue? Here I have tried to add more textfield by addRow function.
– Ashane Alvis
Nov 8 at 11:47
1
You don't, and you don't have to. Create the entire structure using Razor and give the client the last index used:
var lastIndex = @i;
. Even more, that won't work as you would expect once in the client, the constants will work, but the indexers not.– Camilo Terevinto
Nov 8 at 11:48
Can you give me an example? On how to convert this?
– Ashane Alvis
Nov 8 at 11:50
I would do this: 1. Remove that HTML concatenation. 2. create a Partial View with that structure. 3. Create an Action method so you can call it from the client. 4. use AJAX to get that HTML from the server and then append it to
#TableExtent
as you are already doing.– Camilo Terevinto
Nov 8 at 11:51