Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
133
rated 0 times [  140] [ 7]  / answers: 1 / hits: 38091  / 10 Years ago, sat, may 24, 2014, 12:00:00

I'm working on MVC4
want to set parameter value from Model inside li onclick window.location



Name = MyValue is hard-coded here


How do I set parameter from Model i'm using foreach loop to iterate.



<ul class="my_list">
<li style="position: relative" onclick="window.location='/Mypage?Name=MyValue'">
</li>
</ul>


onclick is in li how can I set my parameter value there ?



More From » jquery

 Answers
26

you can do like this:



<ul class=my_list>
<li style=position: relative onclick=myFunction(5);>
</li>
</ul>


With Razor like this:



@foreach(var item in Model)
{
<li style=position: relative onclick=myFunction(@(item.SomeProperty));>
</li>
}


Javascript:



<script type=text/javascript>

function myFunction(id)
{
window.location='/Mypage?Name='+id;
}

</script>


I am passing 5 but you can pass some variable in it.


[#70861] Thursday, May 22, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
haleeg

Total Points: 703
Total Questions: 100
Total Answers: 98

Location: Dominica
Member since Sat, Nov 5, 2022
2 Years ago
;