我正試圖填充下拉菜單。到目前爲止,香港專業教育學院有:如何填充下拉菜單?
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<HTML>
<HEAD>
<TITLE>NZ Currency Converter</TITLE>
</HEAD>
<BODY>
<p><tr>
<td colspan="2" align="right"> The other currency is:</td>
<td>
<select name="the other currency is:">
<% List<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();
}
}
}
這是目前我的家控制器視圖鏈接到從下拉菜單將被填充到數據庫中。我還能補充些什麼?我是新來的asp.net,並不確定如何web開發的作品,所以任何幫助將不勝感激。在下拉菜單中,而不是國家即時獲取轉換率。任何人都可以幫助如何改變這個選擇作爲國家
有什麼確切的錯誤信息? – J0HN
object refence未設置爲對象的實例.Exchrate高亮顯示 – gauri
我看不到您在後面的代碼中設置ViewData [「exchrateList」]'。也許'ViewData [「其他貨幣是:」] = db.exchrates.ToList();'應該'ViewData [「exchrateList」] = db.exchrates.ToList();'? – J0HN