从文本框中获取多个值

时间:2013-05-02 13:20:08

标签: jquery asp.net-mvc kendo-ui

我正在使用MVC 3.0 .NET 4.0,Razor和Kendo UI框架。

我有树文本框,我需要从每个文本框中获取值并传递给MVC控制器。

我无法从文本框中接收值。

IE:

file.cshtml

<input type="text" id="tb0" />
<input type="text" id="tb1" />
<input type="text" id="tb2" />

<button type="submit" id="btnSave">Send</button>

jsfile.js

$('#btnSave').click(function (e) {
    e.preventDefault();

  var variable1 = new Array(); //I dont know how to send this values to the controller
  variable1[0] = $('#tb0').val();
  variable1[1] = $('#tb1').val();
  variable1[2] = $('#tb2').val();

  var model = {

     representative1: variable1

  }

  $.ajax({

     url: rootFolder + 'Controller1/Method1',
     type: 'POST',
     data: JSON.stringify(model), 
     dataType: 'json',
     processData: false,
     contentType: 'application/json; charset=utf-8',
     success: OnSuccessSave,
     error: function (jqXHR, textStatus, errorThrown) {
     alert(genericError);

    }
  });
}

的Class1.cs

public class Class1
{
        public Class1()
        {
           this.representative1 = new Representative();
        }

        public int ID { get; set; }
        public string Nombre { get; set; }
        public Representative representative1 {get; set;}
 }

Representant.cs

public class Representative
{
       public string tb0 { get; set; }
       public string tb1 { get; set; }
       public string tb2 { get; set; }
}

Controller1.cs

public class Controller1
{
    [HttpPost]
    public JsonResult Method1 (Class1 model) 
    {
        //The "model" var dont receive the textboxes values.

        return Json(model, JsonRequestBehavior.AllowGet);

    }
}

0 个答案:

没有答案