Reputation: 53
i had build a web form with autocomplete method, the program is working fine in IDE. But after i publish the application to IIS, the method is not working. the console show this error `failed to load resouces: server response with a status 500(internal server error) Index2) . Im suspected the jquery code didn't recognize the controller name.
CSHTML
<script type="text/javascript">
$(document).ready(function () {
$("#CardName").autocomplete({
source: function (request, response) {
$.ajax({
url: "Index2",
type: "POST",
dataType: "json",
data: { Prefix: request.term },
success: function (data) {
response($.map(data, function (item) {
return { label: item.CardName, value: item.CardId };
}))
}
})
},
messages: {
noResults: "", results: ""
}
});
})
</script>
Controller
[HttpPost]
public JsonResult Index2(string Prefix)
{
List<CardHolderDetails> getCardList = new List<CardHolderDetails>();
getCardList = _service.getCardList();
List<CardHolderDetails> ObjList = new List<CardHolderDetails>();
foreach (var value in getCardList)
{
ObjList.Add(new CardHolderDetails { CardId = value.CardId, CardName = value.CardName });
}
//Searching records from list using LINQ query
var CardName= (from N in ObjList
where N.CardName.StartsWith(Prefix)
select new { N.CardName, N.CardId });
return Json(CardName, JsonRequestBehavior.AllowGet);
}
The following code it is working fine during the development, but once publish to IIS it seem the jquery url
cannot be read. any replacement for URL
to controller function name?
Upvotes: 1
Views: 45898
Reputation: 1559
If your _service.getCardList()
returns null
then the foreach
will throw an exception which you have not handled.
Maybe that is the reason you are getting (500) internal server error
and not the jquery url
, as 500 error code suggests that something went wrong in the server code.
As a suggestion, You should use implement try - catch
and log the exceptions somewhere to be able to resolve such issues.
Upvotes: 1