ASP.NET MVC: How to show value in a label from selected Drop Down List item?
Posted
by Lillie
on Stack Overflow
See other posts from Stack Overflow
or by Lillie
Published on 2010-02-26T12:55:08Z
Indexed on
2010/03/19
21:01 UTC
Read the original article
Hit count: 143
jQuery
|asp.net-mvc
Hi!
I'm trying to show a value of selected Drop Down List item in a label. I managed to make this work with Web Forms but with MVC I'm totally lost. My Index looks like this:
[...]
<% using (Html.BeginForm()) { %>
<table>
<tr>
<td>Processor</td>
<td><%= Html.DropDownList("lstProcessor1", new SelectList((IEnumerable)ViewData["Processor1List"], "product_price", "product_description")) %></td>
</tr>
<tr>
<td>Total Amount</td>
<td>0,00 €</td>
</tr>
</table>
<input type="submit" value="Submit" />
<% } %>
[...]
And my HomeController starts with:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using MvcApplication1.Models;
namespace MvcApplication1.Controllers
{
[HandleError]
public class HomeController : Controller
{
// Connect database
DB50DataContext _ctx = new DB50DataContext();
// GET: /Home/
public ActionResult Index()
{
// Search: Processors
var products = from prod in _ctx.products
where prod.product_searchcode == "processor1"
select prod;
ViewData["Processort1List"] = products;
return View();
}
I would like the product_price to show on the second line of the table, where it now says 0,00 €. It should also update the price automatically when the item from the Drop Down List is changed.
I guess I should use JQuery but I have no idea how. Could someone please give me some tips how to do this?
© Stack Overflow or respective owner