To talk about the problem you have there is no direct method/attribute which can only respond to ajax request only.However you can create your own attribute which will respond to ajax request.
In MVC ajax request can be intercepted with Request.IsAjaxRequest()
Here is a code snippet:
public class isAjaxAttribute : ActionMethodSelectorAttribute
{
public override bool IsValidRequest(ControllerContext controllerContext, MethodInfo methodInfo)
{
return controllerContext.RequestContext.HttpContext.Request.IsAjaxRequest();
}
}
Now you can use this attribute on your controller method like
[isAjax]
public ActionResult ajaxMethod()
{
}