Unable to hit a Specific action using Ajax.BeginForm

avnish
avnish
Participant
84 Points
27 Posts

Controller: 

public class HomeController : Controller
{

//
// GET: /Home/

[HttpGet]
public ActionResult ModelUse()
{
return View();
}

[HttpPost]
[ActionName("ModelUse")]
public ActionResult AjaxAdd()
{
return Content("Avnish");
}

public ActionResult AjaxAdd1()
{
return Content("Avnish1234");
}

}

VIEW:

@using (Ajax.BeginForm("AjaxAdd1","Home", new AjaxOptions { UpdateTargetId = "AjaxAdd", HttpMethod = "post" }))
{
<button>Click</button> <div id="AjaxAdd"></div>
}

I am not able to hit AjaxAdd1 ActionResult.

Views: 8173
Total Answered: 3
Total Marked As Answer: 0
Posted On: 04-Sep-2015 10:22

Share:   fb twitter linkedin
Answers
Brian
Brian
Participant
570 Points
75 Posts
         

Hi Avnish,

I checked your code. It's working fine. also hits the AjaxAdd1 action as:

View: ModelUse 

@{
ViewBag.Title ="ModelUse";
Layout ="~/Views/Shared/_Layout.cshtml";
}
<h2>ModelUse</h2>
@using (Ajax.BeginForm("AjaxAdd1", "Home", new AjaxOptions { UpdateTargetId = "AjaxAdd", HttpMethod = "post" }))
{
<button>Click</button> <div id="AjaxAdd"></div>
}

 

Posted On: 04-Sep-2015 22:52
avnish
avnish
Participant
84 Points
27 Posts
         

VIEW:

 

<!DOCTYPE html>

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>ModelUse</title>
<script src="~/Scripts/jquery-1.8.3.intellisense.js"></script>
<script src="~/Scripts/jquery-1.8.3.js"></script>
<script src="~/Scripts/jquery-1.8.3.min.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
</head>
<body>
<div>

<input type="text" value="Submit" />
<input id="Button1" type="button" formmethod="post" value="button" />
</div>
@using (Ajax.BeginForm("AjaxAdd1","Home", new AjaxOptions { UpdateTargetId = "AjaxAdd", HttpMethod = "post" }))
{
<button>Click</button> <div id="AjaxAdd"></div>
}
</body>

</html>
 

CONTROLLER:

public class HomeController : Controller
{
//
// GET: /Home/

[HttpGet]
public ActionResult ModelUse()
{

return View();
}

[HttpPost]
[ActionName("ModelUse")]
public ActionResult AjaxAdd()
{

return Content("ModelUse");
}
[HttpPost]
public ActionResult AjaxAdd1()
{

return Content("AjaxAdd1");
}
}
 
 

Still i am not Able to hit AjaxAdd1 Please help me with this code or give me your code snippet

Posted On: 05-Sep-2015 09:40
Rahul Maurya
Rahul M...
Moderator
1172 Points
211 Posts
         

Hi Avnish,

Just remove the code from view:

<input type="text" value="Submit" />
<input id="Button1" type="button" formmethod="post" value="button" />

And click button from this code:

<button>Click</button>

See Screenshot as:

Posted On: 05-Sep-2015 10:16
 Log In to Chat