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
Istudent Rana
1.4k
342
84k
string value is saving as null in database
Jan 22 2018 10:34 AM
Data type of column in database table is nvarchar(max) and allow null is checked.
This is my code.
This is my ajax post request.
$.ajax({
url: "/Home/SaveAnswer",
type: 'POST',
data: {
"ProjectId": "1",
"QuestionId": qId,
"Answer": text + ',' + rate,
},
cache: false,
}).done(function (response) {
console.log(response);
}).fail(function (e) {
console.log(e);
});
});
Code in controller
[HttpPost]
public string SaveAnswer(AnswerVM model)
{
string msg = "";
try
{
using(MyDbContext context = new MyDbContext())
{
Answer ans = null;
if(ModelState.IsValid)
{
ans = context.Answers.FirstOrDefault(a => a.ProjectId == model.ProjectId && a.QuestionId == model.QuestionId);
if(ans != null)
{
ans.Answer1 = model.Answer;
msg = "ans is not null - {" + ans.Answer1 + "}";
}
else
{
ans = new Answer();
ans.Answer1 = model.Answer;
ans.ProjectId = model.ProjectId;
ans.QuestionId = model.QuestionId;
context.Answers.Add(ans);
msg = "ans is null - {" + ans.Answer1 + "}";
}
context.SaveChanges();
}
}
return msg;
}
catch(System.Exception ex)
{
return ex.Message;
}
}
Reply
Answers (
4
)
What is Dry im mvc
iTextSharp.tool.xml.exceptions.RuntimeWorkerException: 'Inva