Reputation: 12294
ok i have a create/Index/23 view . the create method in the index controller is getting the value of the id when the dropdown event is triggered in the grid. no problem
but there is the search option in my page as well which has ajax.beginform as well. clicking the button there and calling the search method in the index controller is not having the id value which is present in the url . how would i get the id value in the controller . i hope that the question is clear.
Edit: this is the code snippet down here , clicking the button down here will trigger the Search method in the Controller ( which is not getting the id value )
Create.aspx
<% using (Ajax.BeginForm("Search", new AjaxOptions { UpdateTargetId = "divGrid", OnComplete = "OnComp" })) {%>
<%: Html.DropDownList("SelectedsItem", JobHelper.JobSelectStatusDropDown() as IEnumerable<SelectListItem>)%>
<input type="submit" value="Search" />
<% } %>
<% if (Model.Count() > 0)
{ %>
<div id="divGrid">
<% Html.RenderPartial("Manage", this.Model); %>
</div>
<% } %>
Solved using the global.asax
Upvotes: 0
Views: 3056
Reputation: 9815
You need a parameter in your controller action to catch the ID
something like this
public ActionResult Index(int id) {...}
For AJAX requests using jquery you can do this
public JsonResult Search(int id) {...}
In your jQuery
$.ajax({
type: 'POST',
url: '/Controller/Search/',
data: "{'id': '" + yourIDGoesHere + "' }",
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function(data) {},
error: function(e) {}
});
Check out this post with details on what I imagine you're trying to accomplish
http://davidhayden.com/blog/dave/archive/2009/05/19/ASPNETMVCAjaxBeginForm.aspx
Upvotes: 1