希望有好心帮我,这可能是一个简单的问题控制器,但我感到沮丧,因为没有为它的修复,如何发送隐藏字段,通过模型绑定
我想从一个隐藏字段传递值通过模型绑定到控制器, 无论什么方法,我使用,只需从视图中传递值通过模型控制器能为我工作,
这是我的滑块范围
<label for="amount">دامنه قیمت:</label>
<div id="connect" class="noUi-target noUi-ltr noUi-horizontal noUi-background">
</div>
这是隐藏字段,
<input type="hidden" name="MinPrice" value="@Model.MinPrice" id="MinPrice" />
<input type="hidden" name="MaxPrice" value="@Model.MaxPrice" id="MaxPrice" />
<script>
var connectSlider = document.getElementById('connect');
noUiSlider.create(connectSlider, {
start: [40000, 800000],
connect: true,
range: {
'min': 0,
'max': 2000000
}
}); < /script>
<script>
var connectBar = document.createElement('div'),
connectBase = connectSlider.querySelector('.noUi-base');
// Give the bar a class
for styling and add it to the slider.
connectBar.className += 'connect';
connectBase.appendChild(connectBar);
connectSlider.noUiSlider.on('update', function(values, handle, a, b, handlePositions) {
var offset = handlePositions[handle];
// Right offset is 100% - left offset
if (handle === 1) {
offset = 100 - offset;
}
// Pick left for the first handle, right for the second.
connectBar.style[handle ? 'right' : 'left'] = offset + '%';
}); < /script>
<script>
var valueInput = document.getElementById('MinPrice'),
valueSpan = document.getElementById('MaxPrice');
// When the slider value changes, update the input and span
connectSlider.noUiSlider.on('update', function(values, handle) {
if (handle) {
valueInput.value = values[handle];
} else {
valueSpan.innerHTML = values[handle];
}
});
// When the input changes, set the slider value
valueInput.addEventListener('change', function() {
connectSlider.noUiSlider.set([null, this.value]);
});
< /script>
这是我的JS,填补了隐藏字段,这两个字段填写正确,但不要通过型号向控制器发送数据,
感谢各位朋友,
更新
这是我的模型:
public class SearchModel
{
public string Devision { get; set; }
public string Gender { get; set; }
public int? MinPrice { get; set; }
public int? MaxPrice { get; set; }
public string Brand { get; set; }
public string Sport { get; set; }
public string Size { get; set; }
public string ProductGroup { get; set; }
public List<tblSiteItem> Result { get; set; }
public List<tblSiteItem> Sales { get; set; }
public List<string> Devisions { get; set; }
public List<string> Genders { get; set; }
public List<string> Brands { get; set; }
public List<string> Sports { get; set; }
public List<string> Sizes { get; set; }
public List<string> ProductGroups { get; set; }
public List<tblSiteCart> CartItems { get; set; }
public int PageNo { get; set; }
public int Barcode { get; set; }
}
正如我所说的值是否正确填写,所以我不需要代码,使其更正,只是不将hdnValue绑定到我的模型中的字段。 我的意思是MinPrice和MaxPrice。
编辑 我不能悲伤地上传图片,如果我的一切是相当明显的看, 什么办法,我解释一下细节:
当我改变了slideBar,我的JS的火灾和值的变化,
当我点击搜索按钮我的模型中的所有领域是除了这两个领域的领域,我的意思是MinPrice和MaxPrice
结果显示空白页,又是我的js不断射击,然后回来为默认值,
我改变了隐藏字段类型=“文本” 和锯当我更改滑动条时,该值在我的文本框中,但在触摸搜索按钮时未绑定到我的视图模型。
我肯定有什么毛病我的视图模型,但我怎么能明白什么是不正确:(请您看看我的代码
在你的榜样了你编写你的价值我希望成为一个Model.MinPrice,与我希望看到我的模型充满了这个在控制器 – sariiia
**数据试试这个:** 而不是价值=“YourValue”你可以把值=“@ Model.MinPrice”。 –
我测试了这个太多,但没有成功,请查看有一个字段必须更新的帖子,感谢您的时间我的朋友 – sariiia