how to pass parameter to a jquery function from a button click in Asp.net -
i'm new in .net.i'm creating web site using asp.net mvc4. didn't find solution pass parameter jquery function. part of code:
$(function () { $("#aa").dialog({ autoopen: false }); $("#aa").dialog({ showeffect: "fade", hideeffect: "fade", minimizable: true, maximizable: true, modal: true, buttons: [{ text: "yes", icon: "ui-icon-check", click: function (iddel) { window.location.href = "@url.action("supp","company",new { id= *********** })"; } },
[...]
i want pass item.id_company in place of * ?
first, 'item' must have attribute allowing stand out remaining elements of html, example: name, type, id, class, data element...
so, if 'item' has id="idcompany" (for example), can value this: $("#idcompany").val()
i can see have javascript on html page, possibly can directly model.id_company
supose
update: read have button detect possible bug on onclick event. think want this:
onclick="function(@item.id_company)"
instead
onclick="function(item.id_company)"
with @ pass value on model property, without passing string. supose 'function' example, in place must have name of pretended function (for example: onclick="saveid(@item.id_company)"
) or entire code inside function (for example: onclick="return confirm('the id = @item.id_company saved!')"
)
update:
i normaly want anchor element, this:
<a class="mybt" data-url="@url.action("myaction", "mycontroller", new { area = "", myparamter= item.myproperty })">some text</a>
and then, in js file this:
$(".mybt").click(myfunction($(this))); function myfunction(button) { var urlinbt = $(button).data("url"); $("#dialog").dialog({ autoopen: false, height: 500, width: 700, modal: true, buttons: { "ok": function () { if (!isstringempty(urlinbt )) window.location.href = urlinbt ; }, "cancel": function () { $("#dialog").dialog("close"); } }, close: function () { $("#dialog").dialog("close"); $("#dialog").empty(); } }); $("#dialog").dialog("open"); }
depends want url action
Comments
Post a Comment