Javascript 我想填充一个下拉列表并相应地填充一个文本框?

Javascript 我想填充一个下拉列表并相应地填充一个文本框?,javascript,asp.net-mvc,asp.net-mvc-3,model-view-controller,Javascript,Asp.net Mvc,Asp.net Mvc 3,Model View Controller,我有两个下拉列表,我想,如果我从这两个下拉列表中选择某个内容,第三个文本框将使用java脚本自动填充,如。。。 这是我的控制器 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using CommerceSuite.Web.Models.Product; using CommerceSuite.Services; using Com

我有两个下拉列表,我想,如果我从这两个下拉列表中选择某个内容,第三个文本框将使用java脚本自动填充,如。。。 这是我的控制器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CommerceSuite.Web.Models.Product;
using CommerceSuite.Services;
using CommerceSuite.Web.Models.AdjustStock;
using CommerceSuite.Data.Models;

namespace CommerceSuite.Web.Controllers
{
public class AdjustStockController : Controller
{
    private readonly IProductStockService _productStock;
    private readonly IProductService _product;
    private readonly ILocationDetailService _locationDetail;
    public AdjustStockController(IProductStockService productStock, IProductService product, ILocationDetailService locationDetail)
    {
        this._productStock = productStock;
        this._product = product;
        this._locationDetail = locationDetail;
    }
    //
    // GET: /AdjustStock/

    public ActionResult Index()
    {
        var model = new AdjustStockModel();
        model.products = PopulateProductId();
        model.locations = PopulateLocation();
        return PartialView("_AdjustStock", model);
    }

    [HttpGet]
    public ActionResult StockAdjust()
    {
        var model = new AdjustStockModel();
        return PartialView("_AdjustStock",model);
    }

    private List<SelectListItem> PopulateProductId()
    {
        var collectionProduct = new SelectList(_product.GetAllProduct(), "ProductId", "Name").ToList();
        return collectionProduct;
    }
    private List<SelectListItem> PopulateLocation()
    {
        var collectionLocation = new SelectList(_locationDetail.GetAllLocationDetail(), "LocationId", "Name").ToList();
        return collectionLocation;
    }

    CommerceSuiteWMDBContext context = new CommerceSuiteWMDBContext();
    public JsonResult GetData(AdjustStockModel model)
    {
       var data = context.ProductStocks.Where(o => o.ProductId == model.ProductId && o.LocationId == model.LocationId);
       var data = (from t in context.ProductStocks
                   where t.ProductId == model.ProductId && t.LocationId == model.LocationId
                    select t).SingleOrDefault();
        var jsonData = new
        {
            quantity=data.QuantityAvailable
        };
        return Json(jsonData, JsonRequestBehavior.AllowGet);
    }
这是我的观点

@model CommerceSuite.Web.Models.AdjustStock.AdjustStockModel



@Html.ValidationSummary(true)

    <div class="editor-label">
        @Html.LabelFor(model => model.ProductId)

    </div>
    <div class="editor-field">
        @Html.DropDownListFor(model => model.ProductId, Model.products, "Select Product")
        @Html.ValidationMessageFor(model => model.ProductId)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.LocationId)
    </div>
    <div class="editor-field">
        @Html.DropDownListFor(model=>model.LocationId,Model.locations,"Select Location")
        @Html.ValidationMessageFor(model => model.LocationId)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.SystemStock)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model=>model.SystemStock)
        @Html.ValidationMessageFor(model => model.SystemStock)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.ActualStock)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model=>model.ActualStock)
        @Html.ValidationMessageFor(model => model.ActualStock)
    </div>

    <br />

    <div class="block-footer align-right">
        <input type="submit" id="popupConfirmBtn" class="big-button" value="Confirm" />
        <input id="popupCloseBtn" type="button" class="big-button" value="Cancel" onclick="csPopupClose()" />
    </div>

    <div id="popLoading" style="display:none; position:absolute; margin-top:-180px; margin-left:150px; border:none;">
        <img src="../../Content/images/loader.gif" alt="Loading" />
    </div>

现在我如何编写java脚本来实现这一功能。这样,当我选择任何Dropbox时,一个文本框将根据Json返回的值自动填充。

由于您使用的是MVC,我将查看。您可以通过NuGet添加它。有一个更新div的下拉列表。网上有很多文档丰富的示例和教程。

事实上,对于lambda表达式,我不知道如何从下拉列表将id传递给java脚本。