调用Action方法后出现Jquery错误。 [英] Jquery error after calling the the Action Method.
问题描述
嗨专家,
JQuery返回错误:'加载错误...'但控制器工作正常。
JQuery通过完美控制器的值,控制器返回正常,但仍然有错误。
我不知道这有什么问题。
请帮帮我!
控制器:
<前lang =c#> [HttpPost]
public ActionResult EditNews( string value )
{
long id = long .Pars( value < /跨度>);
新闻新闻= .... // 一些返回有效新闻的查询
return PartialView(新闻);
}
查看:
@model MyProject.ViewModels.NewsViewModel
@ Html.ListBoxFor(m => m.SelectedNews,Model.News,
new {id =newsListBox,size = 10,data_url = Url.Action(EditNews,News)})
和JQuery功能:
< pre lang =Javascript> $( function (){
$(' #newsListBox')。change( function (){
var selectedValue = $( this )。val();
$ .ajax({
url:$( this )。data(' url'),
dataType:' text',
type:' POST',
cache: false ,
data: value = + selectedValue,
成功:功能(结果) {
alert(' 它很好 ' );
},
错误:函数(结果){
alert('错误在 loading ... ' );
}
});
});
});
( function () {
(' #newsListBox')。change(< span class =code-keyword> function
(){
var selectedValue =
( this )。val();
Hi experts,
JQuery returns error: 'Error in loading...' But the controller works fine.
JQuery passes value to controller perfectly and the controller returns fine but there is still an error.
I don't know what's wrong with this.
Please help me!
Controller:
[HttpPost]
public ActionResult EditNews(string value)
{
long id = long.Pars(value);
News news = ....//Some query that returns a valid news
return PartialView(news);
}
View:
@model MyProject.ViewModels.NewsViewModel
@Html.ListBoxFor(m => m.SelectedNews, Model.News,
new {id="newsListBox", size=10 ,data_url = Url.Action("EditNews", "News" ) })
And JQuery function:
$(function () {
$('#newsListBox').change(function () {
var selectedValue = $(this).val();
$.ajax({
url: $(this).data('url'),
dataType: 'text',
type: 'POST',
cache: false,
data: "value=" + selectedValue,
success: function (result) {
alert('It's fine');
},
error: function (result) {
alert('Error in loading...');
}
});
});
});
(function () {
('#newsListBox').change(function () { var selectedValue =
(this).val();
这篇关于调用Action方法后出现Jquery错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!