Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 将dropbox值传递给HttpGet操作提交按钮单击?_Html_Asp.net Mvc 3_Razor - Fatal编程技术网

Html 将dropbox值传递给HttpGet操作提交按钮单击?

Html 将dropbox值传递给HttpGet操作提交按钮单击?,html,asp.net-mvc-3,razor,Html,Asp.net Mvc 3,Razor,基本上,我试图将dropbox的值传递给get操作。 “提交”按钮重新指向正确的操作,但使用重新方向添加dropbox值的正确方法是什么 我的看法是: @model TrackerModel @using (Html.BeginForm("MyAction", "MyController", FormMethod.Get, new { ???})) { <div> <strong>@Html.LabelFor(m =>

基本上,我试图将dropbox的值传递给get操作。 “提交”按钮重新指向正确的操作,但使用重新方向添加dropbox值的正确方法是什么

我的看法是:

 @model TrackerModel
     @using (Html.BeginForm("MyAction", "MyController", FormMethod.Get, new { ???}))
     {
     <div>
        <strong>@Html.LabelFor(m => m.CustomerName)</strong>
         @Html.TextBoxFor(m => m.CustomerName, new { type = "hidden", @class = "customer-picker" })
     </div>
     <button class="styledbutton" onclick="window.location.href='/Tracker/Index'">Cancel</button>
     <button type="submit" value="submit" id="selectCustomer-button" class="styledbutton">Submit</button>
 }
 [HttpGet]
 public ActionResult MyAction(IPrincipal user, Tracker model)
})

功能定制器{

$('.customer-picker').select2({
    placeholder: 'Select customer',
    minimumInputLength: 1,
    ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
        url: '/JsonData/GetCustomers',
        type: 'POST',
        dataType: 'json',
        data: function (term) {
            return {
                query: term // search term
            };
        },
        results: function (data) { // parse the results into the format expected by Select2.
            // since we are using custom formatting functions we do not need to alter remote JSON data
            return { results: data };
        }
    },
    formatResult: function (data) {
        return data;
    },
    formatSelection: function (data) {
        return data;
    }
});
}

我希望该值在操作中位于我的Tracker model参数内,但这将返回null。另外,我不确定在表单标记的新参数中放置什么

我还尝试了以下操作,但返回控制器的只是文本:

   @Html.TextBoxFor(m => m.CustomerName, new { type = "hidden", @id = "selectedCustomer", @class = "customer-picker" })

     <script type="text/javascript">
$(function () {
    $("#Form1").submit(function (e) {
        alert("boo");
        e.preventDefault();
        var selectCustValue = $("#selectedCustomer").val();
        $.ajax({
            url: '/CalibrationViewer/SentMultipleCalsToCustomer',
            data: { text: selectCustValue }
        });
    });
});
好的,明白了

   var selectCustValue = $("#s2id_CustomerName span").text();
找到了客户选择器使用的另一段代码,以及与上面使用的视图关联的javascript

我查看了页面源代码,它仍然显示了作为CustomerName的id和名称,这与select2helper有关


考虑到我本应该早点找到答案,我可能会把这个作为答案,但你已经找到了

dropbox在哪里???抱歉,TextBoxfor用作dropbox,使用jquery函数…我希望我可以向textbox添加一个Id并以某种方式获取它的值。然后尝试给它一个名称,并在get controller上获取它的值,名称是指在TextBoxfor标记中,例如new{@name=selectedcustomer}。。。。。并将字符串selectedcustomer添加为Get操作中的参数?no joy,单击submit按钮时Get操作中的字符串selectedcustomer参数为空。。。。。。。将按钮标签更改为输入标签会有什么不同吗?
   var selectCustValue = $("#s2id_CustomerName span").text();