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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With