lundi 1 septembre 2014

Passing parameters to javascript button click handler


Vote count:

0




I have a small application in MVC4. It has a grid and every row has two things. 1) ID 2) Button


When user click on a button I need to invoke a javascript function passing ID as an parameter. How can I do this in MVC. I can eaisly do thin in case of . Please help


Below is my code.



@model IEnumerable<Models.Asset>

@{
ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
Id
</th>

<th>
Show
</th>
</tr>

@foreach (var item in Model) {
<tr>
<td width="80">
@item.Id
</td>


<td>
<button class="btnView" onclick="myfunction(@item.someProperty)">Show</button>
///How can I pass @item.someProperty as an parameter to click handler?
</td>
</tr>
}
</table>


<div id="imageDisplay">

<p>

</p>
</div>

@section scripts{
<script type="text/javascript">
$(function () {
$('#imageDisplay').dialog({
autoOpen: false
});

$('.btnView').click(function () {
alert('ok');
//How can I get id as an parameter to this function?
});

});

</script>
}


asked 33 secs ago







Passing parameters to javascript button click handler

Aucun commentaire:

Enregistrer un commentaire