using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Q694264.Controllers
{
[HandleError]
public class HomeController : Controller
{
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
return View();
}
public ActionResult About()
{
return View();
}
[HttpPost]
public string getallName()
{
return @"{
""BankuaiNames"":
[
""板块1"",
""板块2"",
""板块3"",
""板块4"",
""asdf""
]
}";
}
}
}
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Home Page
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2><%: ViewData["Message"] %></h2>
<%-- <p>
To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
</p>--%>
<script type="text/javascript">
window.onload = function () {
$.ajax({
url: "/home/getallName",
type: "POST",
data: "",
dataType: "json",
success: function (data) {
for (var i = 0; i < data.BankuaiNames.length; i++) {
$("#yys").append("<option>" + data.BankuaiNames[i] + "</option>");
}
},
error: function (data) {
alert("err");
}
});
};
</script>
运营商:<select id="yys" name="yys">
<option>--请选择运营商---</option>
</select>
</asp:Content>