2011-06-27 38 views
0

我已經使用jQuery寫了下面的代碼在我看來,當圖像按鈕,用戶點擊的形式應該被提交,但它沒有提交後形式的MVC

<% using (Html.BeginForm("Resumename", "Resumewizard", 
    FormMethod.Post, new { name = "Resumetitle",OnLoad="Error();"})){ %> 
    <%=Html.Label("Step 1.Resume Name")%><br /> 
    <%=Html.Label("Please Enter Resume Name,Job Title and Objective")%><br /> 
    <%=Html.Label("Resume Name")%><br /> 
    <%=Html.TextBox("ResTitle")%><br /> 
    <%=Html.Label("Desired Job Title/Position")%><br /> 
    <%=Html.TextBox("DesPos")%><br /> 
    <%=Html.Label("Objective")%><br /> 
    <%=Html.TextArea("ResObjective")%><br /> 
    <% string str = ViewData["Errormsg"].ToString(); %> 
    <div id="msgblock"> 
    <%=Html.Label(str)%> 
    <%=Html.Hidden("error", ViewData["Errormsg"])%> 
    <%=Html.Hidden("resumeid",ViewData["resumeid"])%> 
    </div> 
    <input id="SaveForwardButton" type="image" 
    src="../../Content/img/buttons/SaveForwardButton.gif" /> 
<% } %> 
+0

鑑於您的輸出HTML格式有多差,如果您的頁面無效,並且因此無法正確解析,就不會感到意外。我建議根據W3C驗證器驗證輸出html並尋找問題。 –

回答

0

按鈕type設置爲image。我認爲你應該把它改成submit

+1

圖片按鈕也會提交。 –

+0

它不是張貼表格我該怎麼辦 – iProgrammer

+0

你一直說它不張貼。你是什​​麼意思?你的意思是瀏覽器堅決不向服務器發送任何數據?服務器是否收到請求,但沒有按照你想要的方式處理它? –

0

我個人做的,像下面:

<%using (Html.BeginForm("Resumename", "Resumewizard", FormMethod.Post, new { name = "Resumetitle",OnLoad="Error();"})) 
      {%> 
      <%=Html.Label("Step 1.Resume Name")%><br /> 
     <%=Html.Label("Please Enter Resume Name,Job Title and Objective")%><br /> 
     <%=Html.Label("Resume Name")%><br /> 
     <%=Html.TextBox("ResTitle")%><br /> 
     <%=Html.Label("Desired Job Title/Position")%><br /> 
     <%=Html.TextBox("DesPos")%><br /> 
     <%=Html.Label("Objective")%><br /> 
     <%=Html.TextArea("ResObjective")%><br /> 
     <% string str = ViewData["Errormsg"].ToString(); 
      %> 
     <div id="msgblock"> 
     <%=Html.Label(str)%> 
     <%=Html.Hidden("error", ViewData["Errormsg"])%> 
     <%=Html.Hidden("resumeid",ViewData["resumeid"])%> 
     </div> 
     <img class="SaveForwardButton" src="../../Content/img/buttons/SaveForwardButton.gif" /> 

     <script type="text/javascript"> 
     $(".SaveForwardButton").click(function() { 
      $(this).parents("form").trigger("submit"); 
     }); 
     </script> 

<% }%> 

通常我會在我的主.js文件中聲明這個,並將submit類應用於我喜歡的任何元素。

+0

它不會通過此代碼生成點擊事件 – iProgrammer

+0

用於記錄,但此方法可以,但假設用戶擁有JavaScript並不是很好的做法。像asker那樣設置圖像輸入是很好的,那麼如果你想增強它,你可以在之後使用JQuery - 參見「逐步增強」。 – Timbo