gpt4 book ai didi

javascript - ViewBag 值返回错误的数字

转载 作者:行者123 更新时间:2023-12-02 15:55:37 26 4
gpt4 key购买 nike

我正在尝试通过 JavaScript 将 ViewBag 中的值插入到输入中并动态创建该值。

我调用 Controller 创建的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 但在刷新时它会加载错误的数字。

最佳答案

带前导零的整数采用八进制(基数为 8)表示法。

010015001(八进制)= 2103809(十进制)

如果您的 employeeID 字符串包含十进制形式的整数,则应去掉前导零:

string employeeID = @ViewBag.EmployeeID.ToString().TrimStart(new char[]{'0'});

关于javascript - ViewBag 值返回错误的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31570644/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com