我正在开发使用C#和SQL Server 2005中的ASP.NET MVC 3应用程序。
在视图中,我有一个DropDownList,一个按钮。
我怎样才能从DropDownList中删除项目使用AJAX按钮的每一次点击。
我没有使用JQuery,但它引起了我的问题。 逸岸,按钮不能够提交(保存在列表中的某些值)了。
编辑:
局部视图GESTION:
<%@ Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MvcApplication2.Models.FlowViewModel>" %>
<% using (Html.BeginForm("Save", "ProfileGa")) { %>
<%: Html.ValidationSummary(true) %>
<fieldset class="parametrage">
<legend>Gestion de Gamme</legend>
<div>
<%:Html.Label("Poste :")%><%: Html.DropDownListFor(model => model.SelectedPoste, Model.PostesItems, new { @id = "poste" })%>
<input type="checkbox" name="option1" value="Poste Initial" id= "chkMain" onclick="test();"/>Poste Initial
<input type="checkbox" name="option2" value="Poste Final" id= "chkFirst" onclick="test2();"/>Poste Final
</div>
<div>
<%:Html.Label("Nombre de Passage :")%><%: Html.EditorFor(model=>model.Nbr_Passage)%>
</div>
<div class="editor-field">
<%: Html.ValidationMessageFor(model => model.Nbr_Passage)%>
</div>
<div>
<%:Html.Label("Position :")%><%: Html.EditorFor(model=>model.Position)%>
</div>
<%-- <div>
<%:Html.Label("Poste Précédent :")%><%: Html.DropDownListFor(model => model.PostePrecedentSelected, Model.PostesItems)%>
</div>--%>
<div>
<%:Html.Label("Poste Suivant :")%><%: Html.DropDownListFor(model => model.PosteSuivantSelected, Model.PostesItems, new { @id = "dd" })%>
<input type="button" value="Ajouter" id="add" onclick="addtext()"/>
<textarea ID="ta" cols="10" name="S1" rows="8" readonly="true"></textarea>
</div>
<div>
<input type="submit" value="Enregistrer" id="btnSave" />
</div>
</fieldset>
<script type="text/javascript">
function test() {
var chkMain = document.getElementById('chkMain');
var chkFirst = document.getElementById('chkFirst');
if (chkMain.checked) {
chkFirst.disabled = 'disabled';
}
else {
chkFirst.disabled = false;
}
}
</script>
<script type="text/javascript">
function test2() {
var chkMain = document.getElementById('chkMain');
var chkFirst = document.getElementById('chkFirst');
var dd = document.getElementById('dd');
var ta = document.getElementById('ta');
var add = document.getElementById('add');
if (chkFirst.checked) {
chkMain.disabled = 'disabled';
dd.disabled = 'disabled';
ta.value = "Poste0";
add.disabled = 'disabled';
}
else {
chkMain.disabled = false;
dd.disabled = false;
ta.value = "";
add.disabled = false;
}
}
</script>
<script language="javascript" type="text/javascript">
var storedValues = [];
function addtext() {
var dd = document.getElementById('dd');
var ta = document.getElementById('ta');
var add = document.getElementById('add');
var selectedValue = dd.options[dd.selectedIndex].value + " ";
if (storedValues.indexOf(selectedValue) === -1) {
storedValues.push(selectedValue)
ta.value = storedValues.join('')
}
}
</script>
<script type="text/javascript">
$(function () {
$('#btnSave').click(function () {
$('#poste option:selected').remove();
return false;
});
});
</script>
<% } %>
视图索引:
<% using (Html.BeginForm("Save", "ProfileGa"))
{ %>
<div><%:Html.Label("Gamme :")%><%: Html.DropDownListFor(model => model.SelectedProfile_Ga, new SelectList(Model.Profile_GaItems, "ID_Gamme", "ID_Gamme"), new { @id = "gg" })%>
<input type="button" value="Configurer" id="btnShowGestion" onclick="GamDis()"/>
<input type="button" value="Appliquer" id="appliquer" onclick="window.location = 'ProfileGa/Application'"/>
</div>
<div id="divGestion">
<%: Html.Partial("Gestion", Model) %>
</div>
<% } %>
<form id="form1" runat="server">
<fieldset>
<legend>Liste des Gammes</legend>
</fieldset>
</form>
<input type="button" value = "Valider" />
<script type="text/javascript">
$(document).ready(function () {
$('#btnShowGestion').click(function () { $('#divGestion').slideToggle("slow") });
});
</script>
<script type="text/javascript">
function GamDis() {
var gg = document.getElementById('gg');
var bb = document.getElementById('btnShowGestion');
if (gg.disabled) {
gg.removeAttribute("disabled");
} else {
gg.disabled = 'disabled';
}
}
</script>
</asp:Content>
这是梅索德的保存在控制器中的代码:
[HttpPost]
public ActionResult Save(FlowViewModel model)
{
Console.WriteLine("" + model.Nbr_Passage);
if (ModelState.IsValid)
{
Gamme G = new Gamme();
G.ID_Gamme = model.SelectedProfile_Ga;
G.ID_Poste = model.SelectedPoste;
//G.Last_Posts = model.PostePrecedentSelected;
G.Next_Posts = model.PosteSuivantSelected;
G.Nbr_Passage = int.Parse(model.Nbr_Passage);
G.Position = int.Parse(model.Position);
((List<Gamme>)System.Web.HttpContext.Current.Session["GammeList"]).Add(G);
var list = ((List<Gamme>)System.Web.HttpContext.Current.Session["GammeList"]);
}
return RedirectToAction("Index");
}