c# - How can I pass two parameters from ActionLink to ActionResult -
i'm implementing website using asp.net mvc. i'm trying assign role user clicking role. i've tried several ways, unfortunately, failed.
controller method
[httppost,actionname("assignusertorole")] [validateantiforgerytoken] [customauthorize(roles ="sudoadmin")] public actionresult assignusertorole(long userid, long roleid) { new businessuser().addroletouser(userid, roleid); return redirecttoaction("index"); }
view
@html.actionlink(@r.rolename, "assignusertorole", "users", new { userid = model.userid, roleid = r.roleid })
first tried jquery ajax, failed, though think not great idea. however, still "ajax"i mean without refreshing page.
i hope question enough of you
first, action set respond post. means unless request via post, you'll 404, since there's no action can respond other request method.
as link, make request via get. if employ javascript, can bind click
event , send request via post using ajax, again, have send post. if use $.get
or $.ajax
method get, won't work.
ideally, if intend hit action via post, should employ form
element in view. using css, can style submit button link, if that's want, underlying structure should form.
Comments
Post a Comment