ViewData is not working in nopcommerce 4.3

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
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.
3 года назад
Any Update...???
3 года назад
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
3 года назад
Not working. Instance showing that object reference not set to an instance of the object type of error.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.