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

时间:2014-08-19 09:37:43

标签: html asp.net-mvc-3 razor

基本上我正试图将我的Dropbox的值传递给get动作。 提交按钮会重定向到正确的操作,但是通过重定向添加保管箱的值的正确方法是什么?

我的观点:

 @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)

客户选取器

 $(document).ready(function () {
CustomerPicker();

});

函数CustomerPicker(){

$('.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模型参数范围内,但这会返回null。另外我不确定在表单标签中的“new”参数中放置什么?

我也试过以下但是我回到控制器的所有内容都是文字:“”。

   @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 }
        });
    });
});

1 个答案:

答案 0 :(得分:0)

好的,

   var selectCustValue = $("#s2id_CustomerName span").text();

发现另一段代码使用了客户选择器和与上面使用的视图相关的javascript。

我查看了网页来源,它仍然显示ID和姓名为CustomerName,它与&#34;选择2&#34;帮手。

我可能会把这个标记为答案,考虑到我应该早点弄明白,但是你有它!

相关问题