我在需要String
视图参数的控制器中创建了一个动作。鉴于我有一个超链接和onclick
事件,我想调用一个jQuery
函数来将该值发送到操作。
$(function () {
debugger;
$('.delete-icon').click(function () {
//alert($(this.id));
var answer = confirm('Do you want to remove this image?');
var id1 = $('.delete-icon').data('val1');
var jsonval = JSON.stringify(id1);
alert(jsonval);
if (answer) {
$.ajax({
type: 'POST',
contentType: "application/json;charset=utf-8",
//data: { id: jsonval },
//url:'@Url.Action("ImageDelete", "AdminNew")',
url: '/AdminNew/ImageDelete/' + jsonval,
dataType: 'json',
//traditional: true,
success: function (ajaxresult) {
$("#" + jsonval).remove();
},
failure: function (ajaxresult, status) {
console.log(ajaxresult)
}
});
return false;
}
return false;
});
});
<table>
<% foreach (var imagealbum in ViewBag.ImageList)
{ %>
<tr id="<%:imagealbum.frame_image_id %>">
<td class="checkbox">
<input id="chk" type="checkbox" checked="checked" /></td>
<td class="image">
<img src="<%:imagealbum.image_path%>" width="50" height="50" />
</td>
<td class="image-name"><%:imagealbum.image_path%> </td>
<td class="image-delete">
<a href="<%:Url.Action("ImageDelete", "AdminNew", new { id = imagealbum.frame_image_id})%>" class="delete-icon" data-val1="<%:imagealbum.frame_image_id%>"></a>
</td>
</tr>
<%} %>
</table>