2010-10-30 37 views
0

我創建的名字AdmissionControlller那裏我已經添加了兩個的ActionResult功能的控制器:創建和發起活動我一直在asp.net MVC,無法開火變化事件在下拉框

// POST: /Admission/Create 
[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult Create(FormCollection collection) 
{ 
    try 
    { 
     // TODO: Add insert logic here 
     return RedirectToAction("Index",collection); 
    } 
    catch 
    { 
     return View(); 
    } 
} 

//Return the List of Subject For the Class Selected 
[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult Details(string className) 
{ 
    var subject = SubjectsModel.SelectSubjectsByClass(className); 
    return PartialView("EntranceMarks", subject); 
} 

現在查看頁面

創建頁

<h2> 
    Create</h2> 
<% using (Html.BeginForm()) 
{%> 
<%= Html.ValidationSummary(true) %> 
<fieldset> 
    <legend>Fields</legend> 
    <div class="editor-label"> 
     <%= Html.LabelFor(model => model.Id) %> 
    </div> 
    <div class="editor-field"> 
     <%= Html.TextBoxFor(model => model.Id) %> 
     <%= Html.ValidationMessageFor(model => model.Id) %> 
    </div> 
    <div class="editor-label"> 
     <%= Html.LabelFor(model => model.PlNo) %> 
    </div> 
    <div class="editor-field"> 
     <%= Html.TextBoxFor(model => model.PlNo) %> 
     <%= Html.ValidationMessageFor(model => model.PlNo) %> 
    </div> 
    <div class="editor-label"> 
     <%= Html.LabelFor(model => model.AdmissionNo) %> 
    </div> 
    <div class="editor-field"> 
     <%= Html.TextBoxFor(model => model.AdmissionNo) %> 
     <%= Html.ValidationMessageFor(model => model.AdmissionNo) %> 
    </div> 
    <div class="editor-label"> 
     <%= Html.LabelFor(model => model.AdmissionDate) %> 
    </div> 
    <div class="editor-field"> 
     <%= Html.TextBoxFor(model => model.AdmissionDate) %> 
     <%= Html.ValidationMessageFor(model => model.AdmissionDate) %> 
    </div> 
    <div class="editor-label"> 
     <%= Html.LabelFor(model => model.FirstName) %> 
    </div> 
    <div class="editor-field"> 
     <%= Html.TextBoxFor(model => model.FirstName) %> 
     <%= Html.ValidationMessageFor(model => model.FirstName) %> 
    </div> 
    <div class="editor-label"> 
     <%= Html.LabelFor(model => model.MiddleName) %> 
    </div> 
    <div class="editor-field"> 
     <%= Html.TextBoxFor(model => model.MiddleName) %> 
     <%= Html.ValidationMessageFor(model => model.MiddleName) %> 
    </div> 
    <div class="editor-label"> 
     <%= Html.LabelFor(model => model.LastName) %> 
    </div> 
    <div class="editor-field"> 
     <%= Html.TextBoxFor(model => model.LastName) %> 
     <%= Html.ValidationMessageFor(model => model.LastName) %> 
    </div> 
    <div class="editor-label"> 
     <%= Html.LabelFor(model => model.Class) %> 
    </div> 
    <%using (Ajax.BeginForm("Details", new AjaxOptions { 
        UpdateTargetId = "EntranceMarks" })) 
    { %> 
    <div class="editor-field"> 
     <%=Html.DropDownList("StudentClass")%> 
    </div> 
    <div class="editor-label"> 
     <%= Html.LabelFor(model => model.Section) %> 
    </div> 
    <div class="editor-field"> 
     <%=Html.DropDownList("Section")%> 
    </div> 
    <div class="editor-label" id="EntranceMarks"> 
    </div> 
    <%} %>  
    <p> 
     <input type="submit" value="Create" /> 
    </p> 
</fieldset> 
<% } %> 
<div> 
    <%= Html.ActionLink("Back to List", "Index") %> 
</div 

現在,當我改變下拉列表框類,我不能觸發事件?

+0

我知道這是你的第一個問題,但這很難理解。請修改您的帖子以修正代碼的格式,刪除所有不必要的代碼,然後解釋您正在討論的事件。它會真正幫助別人回答你的問題。謝謝。 – jordanbtucker 2010-10-30 05:18:38

+0

好多了。我仍然不確定「無法開火」的意思。你想要發生什麼? – jordanbtucker 2010-10-30 05:49:54

回答

1

創建下拉列表時,您需要包含onchange句柄。下面提到的ChangeClass()方法是您需要創建的JavaScript函數的名稱。

<%=Html.DropDownList("StudentClass", new {onchange="ChangeClass()"})%> 

您交替使用jQuery和onchange事件綁定到下拉列表中你感興趣的內容。

$("#StudentClass").change(function() { 
// your logic goes here 
// if you need to populate some other part of the form 
// this method will probably have some ajax call to a specified 
// controller action which return your data. 
}); 

現在,如果你是說你要當你改變下拉提交表單,這可以用

<%=Html.DropDownList("StudentClass", new {onchange="this.form.submit()"})%>