我正在尝试通过javascript将ViewBag
中的值插入到输入中并动态创建值。
我调用使用控制器
创建的employeeID
的值
public string GetEmployeeID(out string idMethod)
{
string ee_Id = string.Empty;
ClientEmployeeSetupDefaults ee_Setup = this.dbContext.ClientEmployeeSetupDefaults.FirstOrDefault(c => c.ClientID == GlobalVariables.Client);
string nextIdSuffix = string.Empty;
idMethod = ee_Setup.EmployeeIDMethod;
switch (idMethod)
{
case IDMethod.Sequence:
ee_Id = NextEmployeeID(ee_Setup.EmployeeIDNext, "", out nextIdSuffix);
break;
case IDMethod.PrefixPlusSeq:
ee_Id = NextEmployeeID(ee_Setup.EmployeeIDNext, ee_Setup.EmployeeIDPrefix, out nextIdSuffix);
break;
}
if (nextIdSuffix != string.Empty)
{
ee_Setup.EmployeeIDNext = nextIdSuffix;
this.dbContext.SaveChanges();
}
return ee_Id;
}
使用ViewBag
@{
ViewBag.Title = "CreateProcess";
string employeeID = @ViewBag.EmployeeID.ToString();
var LoginCode = @ViewBag.LoginCode;
}
用javascript插入
<script>
$(document).ready(function ()
{
alert('doc ready happened ' + @employeeID + ' - ' + @LoginCode);
document.getElementById('LoginCode').value = @LoginCode;
document.getElementById('EmployeeIDs').value = @employeeID.ToString();
});
</script>
我已经完成了调试,每次在010015001
的employeeID上都会返回2103809
,无论它是动态地从数据库中提取还是我对该值进行硬编码。
在此过程中,它也会运行此方法
public ActionResult CreateProcess(string d, string p, string e, string c, string pp)
{
string method;
List<Id_Name> Profiles = GetAvailableProfiles(p, d);
ViewBag.Profiles = Profiles;
ViewBag.LoginCode = GetLoginCode();
string eeID = GetEmployeeID(out method);
ViewBag.EmployeeID = eeID.ToString();
ViewBag.IDMethod = method;
ViewBag.SelectedDepartment = d;
ViewBag.SelectedPosition = p;
ViewBag.SelectedEEClass = c;
ViewBag.SelectedEStatus = e;
ViewBag.DefaultProfile = Profiles[0].ID;
xxx.SignOn = this.dbContext.xxx.Where(obpt => obpt.TaskType == xxx.SignOn && obpt.SetupID == Profiles[0].ID).FirstOrDefault();
ViewBag.SignOnTask = SignOn.TaskID;
return View();
}
我无法弄清楚为什么它会返回该随机数以及为什么通过所有调试它显示正确的010015001
但是在刷新时它会加载错误的数字。
答案 0 :(得分:2)
前导零的整数是八进制(基数为8)。
010015001(八进制)= 2103809(十进制)
如果您的employeeID
字符串包含十进制形式的整数,则应删除前导零:
string employeeID = @ViewBag.EmployeeID.ToString().TrimStart(new char[]{'0'});