小编ade*_*eel的帖子

为什么字符串类型没有转换为int类型?

我想添加两个数字.我从文本框中的按钮获取值.我还成功地将字符串拆分为子字符串,并将这些子字符串的值存储在变量中.但我无法将字符串类型转换为整数类型.这导致连接不是附加的.注意:我正在使用MVC来执行此任务.在模型中value1和value2是模型中的字符串类型这是我的代码片段:

if (button == "1"){
    if (model.textBox == "" || model.textBox == null || model.textBox.ToLower().Contains("please enter value")){
        model.textBox = "1";
    } else {
        model.textBox += "1";
    }
}
if (button == "2") {
    if (model.textBox == "" && model.textBox == null) {
        model.textBox = "2";
    } else {
        model.textBox += "2";
    }
if (button == "+") {
    if (model.textBox == "" && model.textBox == null){
        model.errormsg = "Please enter a number ";
    } else {
        model.textBox += "+";
    }
if …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc

2
推荐指数
1
解决办法
90
查看次数

标签 统计

asp.net-mvc ×1

c# ×1