For far too long I've been stumbling around trying to make a simple .click jquery method work in my c# site. I just want it to call to a function in my controller, but I can't seem to get any button click to register. The calls in it are very similar to a .change() function for another control that works just fine.
JQuery method in question:
$('#addUserButton').click(function () {
var e = document.getElementById('searchDDL');
var itemText = e.options[e.selectedIndex].text;
var url = encodeURI('@Url.Action("AddUser")' + "?User=" + itemText);
});
HTML of button that is intended to trigger the above function:
<button id="addUserButton" type="button" value="addUser">></button>
Some things I've researched and tried already:
- Changing from a .click() method to a .live("click", etc) method made no difference.
- I saw that setting the button type="submit" would be a problem, so I changed it to "button."
- I made sure to include it in document.ready() - I was already doing this before researching other problems.
I have created a jsfiddle for the problem here. I had to remove a lot of sensitive information so the page is not fully fleshed out. It is for an internal application and only has to work with IE.
EDIT: Below I am adding the function I am trying to call in my controller; other posters have verified that the jquery is working as expected, so I'm inclined to believe it is something to do with my c#.
public ActionResult AddUser(string User)
{
//numUsers = App.NumberUsers + 1;
selectedUsers.Add(User);
return RedirectToAction("ApplicationForm");
}