2014-09-12 156 views
0

在我進一步嘗試製作相關數據庫時,我感到奇怪(至少對我而言)表單沒有提交任何值的問題。我的祝福將流動到任何人誰幫助我在這段代碼中發現的問題:表格+表格不提交

***in index.cshtml*** 
<form method = "get" action="update.cshtml" id="mainForm"></form> 
    <table class="database"> 
     <tr> 
      <th>Ocena z informatyki</th> 
      <th>Ocena z fizyki</th> 
      <th>Ocena z matematyki</th> 
      <th>No.</th> 
     </tr> 
     @foreach(var row in db.Query(queryString)) 
     { 
      <tr> 
      <td id="it" ondblclick="edit(this)">@row.it</td> 
      <td id="physics" ondblclick="edit(this)">@row.physics</td> 
      <td id="math" ondblclick="edit(this)">@row.maths</td> 
      <td id="no">@row.no</td> 
      <td><button value="Submit changes" onclick="submit" form="mainForm">Submit changes</button></td> 
      </tr>     
     } 
     </table> 

這裏是「編輯()」函數:

***in scripts.js*** 
function edit(elm) { 
    if (elm.getElementsByTagName('input').length > 0) return; 

    var value = elm.innerHTML; 
    elm.innerHTML = ''; 

    var input = document.createElement('input'); 
    input.setAttribute('type', 'text'); 
    input.setAttribute('value', value); 
    input.setAttribute('form', 'mainForm'); 
    elm.appendChild(input); 
    input.focus(); 
} 
+1

這應該有幫助:http://weblogs.asp.net/scottgu/asp-net-mvc-framework-part-4-handling-form-edit-and-post-scenarios 或觀看此:https:/ /www.youtube.com/watch?v=fsfOFL4bXXA(它有創建表單+提交的演示) – Omu 2014-09-12 17:20:12

+0

表單操作屬性應該看起來像這樣:action =「@ Url.Action(」Home「,」Update「)」 – aleha 2014-09-12 20:55:49

回答

0

如果使用「包含method = get」提交你需要將數據追加到查詢字符串中。