ViewData is not working in nopcommerce 4.3

1 month ago
I want to pass value from controller to view in product list of nopcommerce 4.3. So for that I am using ViewData as well as ViewBag, but both are not working. Surprised...!!! but dont know why...??

Here is my Controller code,

[HttpPost]
public virtual IActionResult ProductList(ProductSearchModel searchModel)
{
    if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
        return AccessDeniedDataTablesJson();

    //prepare model
    var model = _productModelFactory.PrepareProductListModel(searchModel);
    ViewData["PersonName"] = searchModel.SearchTotalNetWeight;
    return Json(model);
}

And I am doing alerting ViewData in view side in datatable footer action.

function stockfootercallback(tfoot, data, start, end, display) {
alert(@ViewData["PersonName"]);
}

But in alert showing blank value, while as per I am seeing there is not an issue in ViewData syntax, still value is not coming.

I used ViewBag also in the place of ViewData but no use of it.
1 month ago
Any Update...???
1 month ago
Hi,

Thanks for the query!!!

You can use TempData instead of ViewData as TempData["PersonName"] = searchModel.SearchTotalNetWeight; on controller and on view side alert("@TempData["PersonName"].ToString()");

Kind Regards
TMotions
1 month ago
Not working. Instance showing that object reference not set to an instance of the object type of error.