2010-09-20 49 views
0

我用这CCODE现在..

<%using (Html.BeginForm("SaveNewServiceTypeCategory","ServiceTypeCategory")){ %> 
     <table> 
     <tr> 
      <td>Service type category:</td> 
      <td style="padding-left:5px;"> 
      <input type="text" id="txtNewServiceTypeCategory" name="txtNewServiceTypeCategory" style="width:400px;" maxlength="30" /> 
      </td> 
     </tr> 
     <tr> 
      <td valign="top">Service type description:</td> 
      <td style="padding-left:5px;"> 
      <textarea id="txtNewServiceTypeCategoryDesc" name="txtNewServiceTypeCategoryDesc" style="width:400px;" rows="3"></textarea> 
      </td> 
     </tr> 
     <tr> 
      <td colspan="2"> 
      <input type="submit" value="Save"/> 
      </td> 
     </tr> 
     </table> 
     <%} %> 

但我需要显示时添加到数据库中的数据弹出消息..

我写了somethign这样

$(function() { 
      $('#form1').submit(function() { 
       $.ajax({ 
        url: , how to give the URl here? 
        type: this.method, 
        data: $(this).serialize(), 
        success: function() { 
         alert("Saved Successfully!"); 
        } 
       }); 
       return false; 
      }); 

保存后需要显示保存成功的消息给用户?

谢谢 });

回答

2

您可以通过给你的身形一个唯一的ID开始:

<% using (Html.BeginForm(
    "SaveNewServiceTypeCategory", 
    "ServiceTypeCategory", 
    FormMethod.Post, 
    new { id = "form1" })) { %> 

然后用这个ID为提交注册事件:

$(function() { 
    $('#form1').submit(function() { 
     $.ajax({ 
      url: this.action, 
      type: this.method, 
      data: $(this).serialize(), 
      success: function (result) { 
       alert('Saved Successfully!'); 
      } 
     }); 
     return false; 
    }); 
}); 

还有它允许你AJAXify的jquery form plugin现有的表格很容易:

$(function() { 
    $('#form1').ajaxForm(function() { 
     alert('Saved Successfully!'); 
    }); 
}); 
+0

感谢您的更新。它做得很好,但它并没有保存到我的数据库中,但它的提示信息已成功保存? – kumar 2010-09-20 19:02:12

+0

也许问题出在你的控制器动作上。你有没有尝试通过代码来验证发生了什么? – 2010-09-20 19:12:21

+0

是的,我没有得到我存储在控制器中的值? – kumar 2010-09-20 19:14:35

相关问题