我有這段代碼,我怎麼能得到@htmlDropDownList的選定值來把這個值放在我的@ Url.Action中而不是,我已經使用javascriptØjQuery的閱讀,但我無法弄清楚如何可以在視圖中直接做的,這是不工作我我怎麼能在@Html.DropDownList中選擇一個值在MVC3
var idempresa = $('IdEmpresa').val()
<a href="@Url.Action("List","Script")?idempresa=**idempresa**"
代碼:
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Script</legend>
<div class="editor-label">
@Html.LabelFor(model => model.IdEmpresa, "Empresa")
</div>
<div class="editor-field">
@Html.DropDownList("IdEmpresa", String.Empty)
@Html.ValidationMessageFor(model => model.IdEmpresa)
</div>
</fieldset>
}
href="@Url.Action("List","Script")?idempresa=**1**"
PD。感謝你的幫助
編輯:
@using System.Web.Mvc.Html
@model SistemaDispositivos.Models.Script
@{
ViewBag.Title = "Script";
}
<h2>Script</h2>
<script src="../../Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Script</legend>
<div class="editor-label">
@Html.LabelFor(model => model.IdEmpresa, "Empresa")
</div>
<div class="editor-field">
@Html.DropDownList("IdEmpresa", String.Empty)
@Html.ValidationMessageFor(model => model.IdEmpresa)
</div>
</fieldset>
}
<script type="text/javascript" language="javascript">
$(document).ready(function() {
var url1 = '@Url.Action("List","Script")?idempresa=';
$('IdEmpresa').change(function() {
$urlId = $('urlid');
$urlId.attr('href', url + $(this).val());
});
});
</script>
<a id="urlid" href="@Url.Action("List","Script")?idempresa=url1"> </a>
什麼IAM缺失?
是什麼你的錯誤?如果沒有這些,不能告訴你什麼是缺失的。 – mccow002