User588019485 posted
I have a listbox where I want to display a list of names concatenated price . The problem is that when the name exceeds a certain length, the price gets pushed to the right. I have tried some code but it doesnt not seems to work properly.
Below is my code
public String stringName(string name,decimal price,int vendorid)
{
if (name.Length > 30)
return name.Substring(0, 30) + _priceFormatter.FormatShippingPrice(Convert.ToDecimal(Nop.Plugin.Data.Import.Classes.Common.GePriceAftertMarkup(price.ToString(), vendorid)), true);
else
return name.PadRight(30 - name.Length) + _priceFormatter.FormatShippingPrice(Convert.ToDecimal(Nop.Plugin.Data.Import.Classes.Common.GePriceAftertMarkup(price.ToString(), vendorid)), true);
}
/// <summary>
///
/// </summary>
/// <param name="subcatid"></param>
/// <returns></returns>
[HttpPost]
public ActionResult LoadProducts(int subcatid)
{
try
{
int[] subcategoryid = new int[1];
subcategoryid[0] = subcatid;
model.ProductList = _productService.SearchProducts(
storeId: _storeContext.CurrentStore.Id,
categoryIds: subcategoryid,
orderBy: ProductSortingEnum.CreatedOn).ToList();
List<CS_Product> Products = new List<CS_Product>();
foreach (var item in model.ProductList)
{
Products.Add(new CS_Product() { ID = item.Id, Name = stringName(item.Name, item.Price,item.VendorId) });
}
return Json(new { ok = true, data = Products, message = "ok" });
}
catch (Exception ex)
{
return Json(new { ok = false, message = ex.Message });
}
}