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
Raju Fodse
1.5k
244
31.3k
Set Value for Filed on Condition in MVC
Sep 24 2018 1:52 AM
I have three Tables in SQL with following fileds
1) Order : [OrderID (pk)], [OrderSize], [Thickness], [OD]
2) PipeAllocation : [PipeNo(PK)], [OrderID (fk)], [Length], [Status]
3) Process: [ProcessID (pk)], [PipeNo(fk)], [Date], [MPP]
for adding record in process table I want set value for MPP on criteria of Thickness so I write following code but I got error of
"
Object reference not set to an instance of an object.
". I dont have any null value in thickness field.
my code is
[HttpPost]
public
ActionResult CreateP3(Process process)
{
var tr = process.StageID + process.PIPENO + process.Status;
var checkme = (from x
in
db.Processes
where x.StageID + x.PIPENO + x.Status == tr && x.Status ==
"OK"
select x).ToList();
if
(checkme.Count > 0)
{
ModelState.AddModelError(
"PIPENO"
,
"You are trying Duplicate Pipe Entry"
);
}
if
(ModelState.IsValid)
{
if
(process.PipeAl.Order.THK > 1)
{
process.MPP = 10;
}
process.CuttingSpeed = (process.ActualMeter*1000)/process.CuttingTime;
db.Processes.Add(process);
db.SaveChanges();
return
RedirectToAction(
"IndexP3"
);
}
var EmpAtnList = db.Attens.ToList();
IEnumerable<SelectListItem> AttnList = from s
in
EmpAtnList.OrderByDescending(s => s.ATTNDATE)
select
new
SelectListItem
{
Value = s.ATTNSYSID.ToString(),
Text = s.ATTNDATE +
"--"
+ s.Emp.EmpName
};
ViewBag.ATTNSYSID =
new
SelectList(AttnList,
"Value"
,
"Text"
);
//ViewBag.ATTNSYSID = new SelectList(db.Attens, "ATTNSYSID", "EMPCODE", process.ATTNSYSID);
ViewBag.StageID =
new
SelectList(db.OMStages,
"StageID"
,
"StageName"
);
ViewBag.NextStageID =
new
SelectList(db.OMStages.OrderBy(x => x.StageValue),
"StageID"
,
"StageName"
);
ViewBag.PIPENO =
new
SelectList(db.PipeAls,
"PIPENO"
,
"PIPENO"
);
ViewBag.Status =
new
SelectList(db.ValueAddLists.Where(x => x.RefName ==
"PipeStatus"
),
"RefValue"
,
"Description"
, process.Status);
return
View(process);
}
Reply
Answers (
14
)
asp.net mvc 5 with portfolio
dose ajax prerequisite Bin folder in solution