Base solution for your next web application
Open Closed

Error when disabling custom filter #933


User avatar
0
sparkyjr created

Hi,

I am new to ASP.Net Zero and ABP.

I have created a custom filter to ignore the rows having IsArchived property set to 1, i.e. true. Everything works fine. It filters out the rows with this column == 1. Now, I want to fetch the rows where IsArchived == 1. I mean, I want to fetch the archived rows now. I tried disabling the custom filter in my controller action, as follows:

public class ArchivedController : Controller
    {
        private ArchivedAppService archivedAppService;
        IUnitOfWorkManager unitOfWorkManager;

        public ArchivedController(IUnitOfWorkManager _unitOfWorkManager, ArchivedAppService _archivedAppService)
        {
            archivedAppService = _archivedAppService;
            unitOfWorkManager = _unitOfWorkManager;
        }

        public ActionResult Index(int id)
        {
            unitOfWorkManager.Current.DisableFilter("ArchiveFilter");  //Error: "Object reference not set to an instance of an object."
            var output = archivedAppService.GetArchived(id);
            ArchivedViewModel model = new ArchivedInitiativesViewModel(output);

            return View(model);
        }
    }

The Current property of unitOfWorkManager is null. So, it throws error.

Please tell me what could be the reason. How and where do I set the unit of work?

Thank you in advance!


2 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Make Index method virtual and add UnitOfWork attribute as follows:

    [UnitOfWork]
    public virtual ActionResult Index(int id)
    {
        ...
    }
    

    Please read UOW document to understand UnitOfWork attribute and virtual relation better: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#DocUowRestrictions">http://www.aspnetboilerplate.com/Pages/ ... strictions</a>

  • User Avatar
    0
    sparkyjr created

    That worked. I will have a look at the UOW document. Thank you so much hikalkan!