Dropbox的值传递给一个HTTPGET行动提交按钮单击? [英] Pass dropbox value to a HttpGet action submit button click?

查看:131
本文介绍了Dropbox的值传递给一个HTTPGET行动提交按钮单击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我想我的Dropbox的值传递给一个get操作。
在提交按钮重新定向到正确的行动,但什么是增加与重新定向Dropbox的?

Basically I'm trying to pass the value of my dropbox to a get action. The submit-button re-directs to the correct action , but what is the correct way to add the value of the dropbox with the re-direction?

我的观点:

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

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

}

我期待值是在我的行动跟踪模型参数之内,但是这将返回空值。另外我不知道该怎么在表单标签中的新的参数放置?

I was expecting the value to be within my Tracker model parameter in the action, but this returns nulls. Also I'm not sure what to place in the "new" parameter in the form tag?

我也试过以下,但我得到的返回控制器的文字:

I also tried the following but all I get returning to the controller is text:"".

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

推荐答案

OK知道了,

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

找到另一片$ C $的c中的使用与视图相关联的客户选择器和JavaScript使用上述

Found another piece of code the used the customer-picker and the javascript associated with view used the above.

我查看网页的源文件,它仍然显示是两个编号,名称和客户名称,它是与选择2的帮手。

I viewed the page source and it still show's both id and name as CustomerName, it has something to do with the "Select 2" helper.

我可能会定于这标志着作为答案,考虑到我应该早点想通了,但你有它!

I may get slated for marking this as the answer, considering I should have figured it out earlier, but there you have it !

这篇关于Dropbox的值传递给一个HTTPGET行动提交按钮单击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆