0

我使用 MVC 3.0 .NET 4.0、Razor 和 Kendo UI 框架。

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

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

IE:

文件.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;}
 }

代表.cs

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

控制器1.cs

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

        return Json(model, JsonRequestBehavior.AllowGet);

    }
}
4

0 回答 0