从Bind获取价值。一键返回“0”

时间:2014-12-11 12:52:31

标签: asp.net-mvc controller

我想用Bind值制作一些字符串。很容易,除了其中一个正在弄乱我。 _surveyID =“0”

SurveyController:

public ActionResult Create([Bind(Include = "SurveyID,SurveyName,SenderID,ConsultantID,ResponderID,Question1,Question2,Question3,Question4,Question5,SurveyTime")] Survey survey)
            {
                if (ModelState.IsValid)
                {     
                    string _surveyID = survey.SurveyID.ToString();
                    string _surveyName = survey.SurveyName;
                    string _surveyTime = survey.SurveyTime.ToString();

                    //ANOTHER ATTEMPT, SAME RESULT
                    //string _surveyID = db.Surveys
                    //.FirstOrDefault(x => x.SurveyID == survey.SurveyID)
                    //.SurveyID;

                }

SurveyID to database = 1002

SurveyID_surveyID =“0”

请注意,_surveyName_surveyTime都正常运作。

survey绑定值:http://i.imgur.com/khEDUns.png

当我尝试提取值时,为什么我的SurveyID设置为0?

编辑:投放到数据库时是否创建了ID值?我的代码在代码流程中是否太快了?

EDIT2:这是一个bump1

0 个答案:

没有答案