0

I have a button on my page that when clicked should redirect to another view based on an Action in my controller, but when clicked it does not do anything... I have the same html syntax with another button on another view and it works.... so here is the broken button:

<input type="button" class="btn btn-info btnArchive clearButton" value="Clear Search" onclick="location.href='@Url.Action("ClearArchiveFilter","ApplicantRecords", new { area = "" })'"  />

Here is the same button but with a different action on another view of mine that works:

<input type="button" class="btn btn-info indexBtns" value="Clear Search" onclick="location.href='@Url.Action("ClearFilter","ApplicantRecords", new { area = "" })'" />

However, if instead of using inline onclick events for the broken button I used JS as a workaround and it works fine:

<script type="text/javascript">
    $(document).ready(function (e) {
        $('.clearButton').click(function (e) {
            location.href = '@Url.Action("ClearArchiveFilter","ApplicantRecords")';
        });
    });
</script>

Here is the ClearArchiveFilter method in my ApplicantRecords Controller:

public ActionResult ClearArchiveFilter()
{
    Session.Clear();
    return RedirectToAction("Archive");
}

Just a quick method to clear a session.

So my question, is that why doesn't my button work? Am I missing something really small? It is just striking me as weird that one button with the same syntax works and the other doesn't... I will stick with the JavaScript method if this can't be explained/resolved.

I have checked spelling multiple times so that is not the issue (at least I hope not and I overlooked a spelling mistake multiple times)

Thanks in advance.

Daniel
  • 9,491
  • 12
  • 50
  • 66
Grizzly
  • 5,873
  • 8
  • 56
  • 109
  • 2
    you [shouldn't use](http://stackoverflow.com/questions/5871640/why-is-using-onclick-in-html-a-bad-practice) inline onclick events anyways – mjr Feb 17 '16 at 19:22
  • Do you have a ClearArchiveFilter method in your ApplicantRecords controller? Also, do you see any errors in your console log (F12 in most browsers) ? – devlin carnate Feb 17 '16 at 19:22
  • Yes I have a `ClearArchiveFilter` method in my `ApplicantRecords` controller.. and I do not see any errors in my console log. – Grizzly Feb 17 '16 at 19:25
  • see my edited question to view the `ClearArchiveFilter` method in my controller – Grizzly Feb 17 '16 at 19:28
  • Try using a different class name. Some .jQuery libraries have special reserved names. Perhaps one is throwing out your onclick because the class is "clearButton". Does "clearButton1" fix it? – Nate Feb 17 '16 at 19:41
  • Class names shouldn't affect an inline event handler for html.. class names would affect the JavaScript portion that I wrote... which is actually the reason I added the `clearButton` class name specifically for the reason of the JavaScript Portion.. so before I wrote the JavaScript, the inline html event handler looked like this: `` – Grizzly Feb 17 '16 at 19:52

0 Answers0