【发布时间】:2014-08-19 09:37:43
【问题描述】:
基本上,我正在尝试将我的保管箱的值传递给 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)
客户选择器
$(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 模型参数内,但这会返回空值。另外我不确定在表单标签的“新”参数中放置什么?
我也尝试了以下方法,但返回到控制器的只是文本:“”。
@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 }
});
});
});
【问题讨论】:
-
保管箱在哪里????
-
抱歉,TextBoxfor 充当保管箱,使用 jquery 函数...我希望我可以在文本框中添加一个 Id 并以某种方式获得它的价值。
-
然后尝试给它一个名称并在 get controller with name 上获取它的值
-
您的意思是在 textboxfor 标签中类似于 new{ @name="selectedcustomer"} ..... 并在 Get 操作中添加字符串 selectedcustomer 作为参数?
-
不高兴,点击提交按钮时,Get 操作上的字符串 selectedCustomer 参数为空......将按钮标签更改为输入标签会有什么不同吗?
标签: html asp.net-mvc-3 razor