0

I need to add an @Html.HiddenFor when a button is clicked

My jquery code is this:

function btnAdd() {

var x;
y = $("#drpDwnPRTPP");  

$("#budgetsList ul").html('<li>Primer elemento ' +
'@Html.HiddenFor(x => Model.ToList()['+ c +'].PRTPP_ID, new { @id="prtppID"'+ c +', @value="'+ y.val() +'" })' +
'</li>'
   ); 
}

But when i clicked this is what i get in my html :

Primer elemento @Html.HiddenFor(x => Model.ToList()[0].PRTPP_ID, new { @id="prtppID"0, @value="1" })

instead an input element

any way to do this ? ? ...

3
  • 3
    You are adding server code on the client.. Commented Sep 5, 2012 at 19:23
  • you will have to make the input manually. Commented Sep 5, 2012 at 19:24
  • yep after looking this, i get like o.O why i ask this ? haha is the hunger man haha Commented Sep 5, 2012 at 19:32

1 Answer 1

3

HTML helpers are server side, Jquery is happening on the client side, so you are going to need to add your hidden field on the client side. See: stackoverflow

Sign up to request clarification or add additional context in comments.

1 Comment

yep, i dont why i ask this,is the hunger that i have, doesnt let me think clearly haha

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.