I am trying to create a user interface in my ASP.NET MVC application for creating plans in stripe. Stripe requires a product ID in order to create a subscription plan, so I need to display a dropdown that lists the available products to the customer.
I have an option where the customer can create products from a form, and this works perfectly, however, I am having trouble understanding how to pass this into Html.DropDownList("ProductId"). I first thought that I would need to save duplicate data in order to achieve this, however, when I tried to do this, I received an error saying that my model has a value of null, because in my method I am creating two products - one in the api, and one locally - I have changed this back to only use the API.
I've tried more than just this, but this is most recent:
public ActionResult Create()
{
StripeList<Product> products = new StripeList<Product>();
ViewBag.Products = new SelectList(products, "Id", "Name");
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create(PlanCreateViewModel model)
{
if (ModelState.IsValid)
{
var options = new PlanCreateOptions
{
Id = model.Id,
Amount = model.Amount,
Currency = model.Currency.ToLower(),
Interval = model.Interval,
Product = model.Product,
IntervalCount = model.IntervalCount,
};
var planService = new PlanService();
await planService.CreateAsync(options);
return RedirectToAction("Index");
}
return View(model);
}
// html helper returns null reference exception
@Html.DropDownList("Products", null, new { @class = "form-control" })
TL;DR: How can I retrieve a list of the stripe products that display the name of the product, but have the value of the product ID in asp.net mvc5.