I know how to respond to a form post in ASP.NET MVC using jQuery, but I’m having trouble with something that is a little bit more simple.
The scenario is that there is a list of items on the screen, like an ordered list.
<ul>
<li>Item 1</li> // each will corrospond with an id.
<li>Item 2</li>
<li>Item 3</li>
</ul>
This is a crude example, of course, but the basic jist is that when the user clicks one, it will perform some server side logic… so in the controller, there is a method such as ..
public bool CheckSomething(int id)
{
// do some logic to determine if the result should be true
return true;
}
It’s very simple logic, really – but it still requires database access, so I cannot do it in javascript. I need to have it hit my controller. The problem is that I want the UI to respond to this.
I’m having a difficult time figuring out how to exactly wire this up without using a Form. Any suggestions?
Use jquery ajax. This example should get you going.
Server:
Client: