$(document).ready(function () {
$("#PartChild").change( function () {
var comment = $(this).val();
if(comment.lenth==0)
{
alert("请输入货品编码!");
return;
}
$.ajax({
url:"/Goods/AddComment",
type:"POST",
dataType:"Json",
data:{comment:comment,action:"AddComment"}, //data这行要加后台的参数名.
success:function(sesponseTest){
if(sesponseTest!=null)
$("#comments").text(sesponseTest)
}
});
})
});
});
[HttpPost]
public ContentResult AddComment(string comment)
{
//_comments.Insert("
" + comment + "");//return Content(string.Join("\n", _comments.ToArray()));
if (comment==null)
{
return Content("请输入货品编码!");
}
Goods goods = db.Goods.Find(comment);
if(goods==null)
{
return Content("货品不存在");
}
return Content(goods.Name);
}
你返回的是Content,ActionResult返回的是Content么?是View哪些吧??
你ajax提交的时候是Post,请问你的接收呢?最起码你也要对应的给一个吧?[HttpPost]行不?