TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Arjun M.R
NA
190
14.2k
Binding image in jquery datatable using asp.net mvc
Oct 11 2020 9:08 AM
Hello everyone,
I tried to bind image inside jquery datatable plugin but it is showing an error 'Not allowed to load local resource: file:///E:/myworks/Demo/Images/Img/16.png' .
I am attaching my code along with it. Please help me to get out of this issue.
$(
'#dataTable'
).DataTable({
ordering:
true
,
searching:
false
,
paging:
false
,
autoWidth:
true
,
processing:
true
,
responsive:
true
,
bSort:
true
,
language: {
"processing"
:
"Loading..."
},
ajax: {
url:
"/Login/GetAllData"
,
type:
"POST"
,
datatype:
"json"
},
pageLength: 7,
columns: [
{
"data"
:
"ID"
,
"name"
:
"ID"
,
"defaultContent"
:
"<i>-</i>"
},
{
"data"
:
"Type"
,
"name"
:
"Type"
,
"defaultContent"
:
"<i>-</i>"
},
{
"data"
:
"To"
,
"name"
:
"To"
,
"defaultContent"
:
"<i>-</i>"
},
{
"data"
:
"ImagePath"
,
"name"
:
"ImagePath"
,
"defaultContent"
:
"<i>-</i>"
,
"render"
:
function
(data, type, row, meta) {
debugger
;
return
'<img src="'
+ data +
'"height="70px" width="40px"/>'
;
}
}
],
columnDefs: [
{ className:
"text-center"
,
"targets"
: [0, 1, 2] },
//{
// "data": "ImagePath",
// "render": function (data, type, row, meta) {
// return '<img src="' + data + '" alt="' + data + '"height="16" width="16"/>';
// }
//}
],
destroy:
true
})
and my controller is given below
try
{
if
(busModelVM.File !=
null
&&busModelVM.File.ContentLength>0)
{
var fileName = Path.GetFileName(busModelVM.File.FileName);
var ext = Path.GetExtension(busModelVM.File.FileName);
string
name = Path.GetFileNameWithoutExtension(fileName);
string
myFile = name + ext;
var path = Path.Combine(Server.MapPath(
"/Images/Img"
),myFile);
busModelVM.File.SaveAs(path);
busModelVM.ImagePath = path;
//string filename = Path.GetFileName(busModelVM.File.FileName);
//string path = Path.Combine(Server.MapPath("~/Images"), Path.GetFileName(file.FileName));
//string imagePath = Path.Combine(Server.MapPath("/Uploads/"), busModelVM.File.FileName);
//var ext = Path.GetExtension(busModelVM.File.FileName);
//string name = Path.GetFileNameWithoutExtension(fileName);
//busModelVM.File.SaveAs(imagePath);
//busModelVM.ImagePath = imagePath;
}
var result = _class1.InsertUpdateData(_mapper.MapToBusMaster(busModelVM), conString);
//return Json(new { data = result }, JsonRequestBehavior.AllowGet);
return
JsonConvert.SerializeObject(
new
{ Status =
"OK"
, Records = result, Message =
"Insertion sucessfull"
});
}
catch
(Exception ex)
{
//return Json(new { data = "" }, JsonRequestBehavior.AllowGet);
return
JsonConvert.SerializeObject(
new
{ Status =
"ERROR"
, Records =
""
, Message = ex });
}
I think it is an issue in saving image path. Please help me to get out of the issue.
Reply
Answers (
4
)
How to fire off an ActionLink (controller method) defined in a view.
Error: SyntaxError: Unexpected token < in JSON