ViewData is not working in nopcommerce 4.3

один месяц назад
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.
один месяц назад
Any Update...???
один месяц назад
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
один месяц назад
Not working. Instance showing that object reference not set to an instance of the object type of error.