开发者

How to populate the pull down menu?

I'm trying to populate the pull down menu. so far ive got:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<HTML>
<HEAD>
<TITLE>NZ Currency Converter</TITLE>
 </HEAD>
<BODY>
<p><tr>
<td colspan="2" align="right">&nbsp;&nbsp;The other currency is:</td>
<td>
  <select name="the other currency is:">
    <% List&l开发者_开发百科t;Currency.Models.exchrate> exchrateList = (List <Currency.Models.exchrate>) ViewData["exchrateList"];
       foreach (Currency.Models.exchrate st in exchrateList)
       {
    %>  
       <option value="<% Response.Write(st.othercurrency);%>">"<% Response.Write(st.fromnzd);%>">"
<% Response.Write (st.tonzd);%>">
</option> 
    <% } %>
    <option value=""></option>
  </select>
     </td>
</tr>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Currency.Models;

namespace Currency.Controllers
{
[HandleError]
public class HomeController : Controller
{
    public ActionResult Index()
    {
        financeInit();
        return View();
    }

    public void financeInit()
    {

        financeEntities db = new financeEntities();
        ViewData["exchrate"] = db.exchrates.ToList();
        ViewData["Convert From NZD"] = "";
        ViewData["Convert To NZD"] = "";
        ViewData["You wish to convert"] = "";
        ViewData["That will produce"] = "";


    }
    public ActionResult financeCurrencyConvert()
    {
        return View();
    }
         }
    }

This is my home controller view currently which is linked to the database from which the pull down menu will be populated. what more can i add to this. i am new to asp.net and not sure how web development works so any help will be appreciated. In the pulldown menu instead of countries im getting their conversion rates. can anyone help with how to change this to select as countries


The issue is that you are using different view data keysin controller and view ("The Other Currency is:" in controller and "exchrateList" in view). Match them and you should be ok - for example, change this line from controller

ViewData["The Other Currency is:"] = db.exchrates.ToList();

to

ViewData["exchrateList"] = db.exchrates.ToList();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜