jquery - How to call my controller action when my button is inside the Json query inside the view page in mvc4? -
jquery - How to call my controller action when my button is inside the Json query inside the view page in mvc4? -
my controller block these:
public actionresult delete(int id) { }
my json code in view page is
for (var = 0; < len; i++) { if (data[i].productid && data[i].name && data[i].shortdescription && data[i].mediumimage && data[i].price && data[i].iconimage) { var photoq = "/images/homeimages/" + data[i].mediumimage; var photo = "<img id='imgad' src='"+ photoq +"' width='100px' height='100px' alt='img'/>"; txt += '<tr><td><div id ="result1" ><div>' + photo + '</div> <div ><div>' + data[i].productid + "</br> name- " + data[i].name + "</br> description " + data[i].shortdescription + ", </br>" + data[i].price+'<input id="btnremove" type="submit" value="remove" />' + "</br>"; }
last line have button id="btnremove" jquery code phone call these is
function deletecart() { $("#btnremove").click(); $.getjson('@url.action("delete", "home")') };
but nil working phone call controller action...plz tell me solution..and tell how pass id through button click event.
if there multiple products (i assume there be, seeing loop), have multiple buttons in page same id, not jquery. suggest, utilize class instead of id.
in posted code, cannot find phone call of deletecart().
i utilize document.ready
event in main view bind click handler dynamic buttons
$(document).ready(function() { $('document').on('click', '.btnremove', function(e) { $.getjson('@url.action("delete", "home")'); }); });
note that, have added 'click' handler document, not button itself, because buttons created dynamically. also, have used class instead of id.
jquery asp.net-mvc-4 json.net
Comments
Post a Comment