Join us this Friday for AI in Action at the Virtual Happy Hour! This free virtual event is open to all—enroll now on Academy and don’t miss out.
Join us this Friday for AI in Action at the Virtual Happy Hour! This free virtual event is open to all—enroll now on Academy and don’t miss out.
This post might be helpful for you: How to post to block controller action? | Optimizely Developer Co
if not, please post the code from your form
Hi,
Just change the [HttpGet] to [HttpPost] and function name to Index.
public class ProductSearchBlockController : BlockController<ProductSearchBlock>
{
private readonly IRepository<Products> _productsRepository;
public ProductSearchBlockController(IRepository<Products> productsRepository)
{
_productsRepository = productsRepository;
}
public override ActionResult Index(ProductSearchBlock currentBlock)
{
var viewModel = new ProductSearchBlockViewModel();
viewModel.Products = _productsRepository.All().ToList();
return PartialView(viewModel);
}
[HttpPost]
public override ActionResult Index(ProductSearchBlock currentBlock)
{
var viewModel = new ProductSearchBlockViewModel();
viewModel.Products = _productsRepository.All().OrderBy(p => p.Price).ToList();
return PartialView(viewModel);
}
}
This is my controller I have a form in the block that hits the OrderBy action however what is returned is the partial file not the page with the block. How can achieve this?
I want to pass in sorted products in the block. When a button is clicked.