I am in a learning process and working on ASP.net MVC 5 project. So, I have a model view which has other model views in it.
Parent Model View
public class FullConfigMV
{
some properties here
public ElementStyleMV Page { get; set; }
}
Now below is what I want to achieve.
Make an ajax call
once the ajax call hits the controller function set some values
now from there I need to pass that object to another controller action which will return it's view.
Step 1.
<script>
$(document).ready(function()
{
$("#tan").change(function()
{
alert(this.value);
$.ajax({
type: 'POST',
url: '/Settings/GetAvailableLocationsFor',
data: { accountId: 28462, groupId: 35},
success: function (data) {
//Whatever
},
error: function () {
DisplayError('Failed to load the data.');
}
});
});
});
</script>
After step 1 my breakpoint hits at
public ActionResult GetAvailableLocationsFor(int accountId, int groupId)
{
FullConfigMV configData = SetLoader.GetDSettings(accountId, groupId);
Utils.SiteCss = configData.CssStyles();
// NOW AT THIS PLACE I WANT TO CALL ANOTHER CONTROLLER FUNCTION
// AND PASS THE `configData Obj`
return View();
}
I know we have something like
return RedirectToAction("Index","Home");
BUT HOW TO PASS THE config Obj
The controller function that I want to call is in
Home Controller and the action name is Index
public ActionResult Index(FullConfigMV data)
{
return View();
}
If the requirement seems weird then kindly bear/humor me on this.
EDIT
After the solution suggested "use TempData " But the problem is I have two index action in my controller. I want the SECOND Index Action to get hit. But the first one is getting hit.
First:
public ActionResult Index()
{
}
Second
[HttpPost]
public ActionResult Index(FullConfigMV data)
{
}
Code used is
public ActionResult GetAvailableLocationsFor(int accountId, int groupId)
{
FullConfigMV configData = SetLoader.GetDSettings(accountId, groupId);
SimUtils.SiteCss = configData.CssStyles();
TempData["config"] = configData;
return RedirectToAction("Index", "Home");
}
RedirectToActioncalls you use Session or TempData. If you just need the (non-view) result from the other controller action -- you move that code into a new class so that any controller can get the result.GetAvailableLocationshave a view, or is it used to process data?