C# .NET - How to redirect to main action when exception occurs in an action returning entity in MVC

Asked By ashish virmani on 08-Apr-13 02:42 AM


private FAQCategoryViewModel FAQCategoryPartial(Entities.Common.AdminSearchParameter searchObject, int Status = 0)

{


FAQCategoryViewModel destination = new FAQCategoryViewModel();


string recordMessage = string.Empty;


int totalRecords = 0;


try

{

searchObject.StatusID = Status;


FAQCategory source = new FAQCategory();

source.lstFAQCategory =


new List<FAQCategory>();

source = ElenaModel.Web.Models.Admin.


AdminModel.Instance.GetFAQCategoryList(searchObject);

AutoMapper.


Mapper.CreateMap<FAQCategory, FAQCategoryViewModel>();

destination = AutoMapper.


Mapper.Map(source, destination);

 


if (source != null && source.lstFAQCategory.Count > 0)

{

totalRecords = source.lstFAQCategory[0].TotalRecords;

}

destination.TotalRecords = totalRecords;

destination.Paging.RecordList = Common.


CommonFunctions.GetPageSize();

destination.Paging.SelectedRecordID = searchObject.Pagger.PageSize.ToString();

destination.Paging.Paging = ShowPagging(totalRecords, searchObject,


out recordMessage);

destination.Paging.RecordMessage = recordMessage;

destination.Paging.NextPageNo = searchObject.Pagger.CurrentPageIndex + 1;

destination.Paging.PrevoiusPageNo = searchObject.Pagger.CurrentPageIndex == 0 ? 0 : searchObject.Pagger.CurrentPageIndex - 1;

destination.Paging.SelectedPageNo = searchObject.Pagger.CurrentPageIndex + 1;


// Save current search in session with new pagger setting

Session[


SessionKeys.AdminSearch] = searchObject;

}


catch (Exception ex)

{

Log.Error(ex);

}


return destination;

}