Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC;并非所有代码路径都返回一个值";_C#_Asp.net Mvc - Fatal编程技术网

C# MVC;并非所有代码路径都返回一个值";

C# MVC;并非所有代码路径都返回一个值";,c#,asp.net-mvc,C#,Asp.net Mvc,我的解决方案有问题。我正在尝试创建一个MVC应用程序,其中视图有一个用于字符串的文本框、一个用于排序类型的下拉列表(例如气泡排序、快速排序)和一个用于排序字符串的按钮 以下是我在控制器中的代码: [HttpPost] public ActionResult total(string value1, String calci) { char[] total; switch (calci) { case "bub

我的解决方案有问题。我正在尝试创建一个MVC应用程序,其中视图有一个用于字符串的文本框、一个用于排序类型的下拉列表(例如气泡排序、快速排序)和一个用于排序字符串的按钮

以下是我在控制器中的代码:

[HttpPost]
    public ActionResult total(string value1, String calci)
    {
        char[] total;
        switch (calci)
        {
            case "bubbleSort":
                total = value1.ToCharArray();
                char temp;
                for (int write = 0; write < total.Length; write++)
                    for (int sor = 0; sor < total.Length - 1; sor++)
                        if (total[sor] > total[sor + 1])
                        {
                            temp = total[sor + 1];
                            total[sor + 1] = total[sor];
                            total[sor] = temp;
                        }
                return Content("Result " + total);

        }
    }
[HttpPost]
public ActionResult总计(字符串值1,字符串calci)
{
字符[]总计;
开关(钙)
{
案例“bubbleSort”:
总计=值1.ToCharArray();
焦炭温度;
for(int write=0;write总计[sor+1])
{
温度=总温度[sor+1];
总计[sor+1]=总计[sor];
总[sor]=温度;
}
返回内容(“结果”+总计);
}
}
它一直给我一个错误“不是所有代码路径都返回值”
我真的需要运行这个程序,也可以忽略actionresult中的“总计”,因为这个项目的原始解决方案是我的计算器项目。谢谢

正如错误试图告诉您的那样,您需要确保函数始终返回一个值


即使错误试图告诉您的
calci
不是
“bubbleSort”

,您也需要确保函数始终返回一个值


即使
calci
不是
“bubbleSort”

,您的问题是在
开关中只有一个返回值。如果案例是“bubbleSort”
,则不会返回任何内容!当您有一个返回类型不是void的方法时,您需要确保所有可能的路由都有一个在创建类时指定类型的返回值

您可以通过添加也返回结果的默认case语句来解决此问题。尝试在第一个
案例之后添加此内容:

default:
    return Content(@"Unhandled 'calci' parameter: " + calci);

您的问题是在
switch
语句中只有一个返回值。如果案例是“bubbleSort”
,则不会返回任何内容!当您有一个返回类型不是void的方法时,您需要确保所有可能的路由都有一个在创建类时指定类型的返回值

您可以通过添加也返回结果的默认case语句来解决此问题。尝试在第一个
案例之后添加此内容:

default:
    return Content(@"Unhandled 'calci' parameter: " + calci);

您将需要如下默认情况:

        switch (calci)
        {
            case "bubbleSort":
                total = value1.ToCharArray();
                char temp;
                for (int write = 0; write < total.Length; write++)
                for (int sor = 0; sor < total.Length - 1; sor++)
                    if (total[sor] > total[sor + 1])
                    {
                        temp = total[sor + 1];
                        total[sor + 1] = total[sor];
                        total[sor] = temp;
                    }
                return Content("Result " + total);
            default:
                return Content("Result 0");                    
        }
开关(calci)
{
案例“bubbleSort”:
总计=值1.ToCharArray();
焦炭温度;
for(int write=0;write总计[sor+1])
{
温度=总温度[sor+1];
总计[sor+1]=总计[sor];
总[sor]=温度;
}
返回内容(“结果”+总计);
违约:
返回内容(“结果0”);
}

您将需要这样一个默认情况:

        switch (calci)
        {
            case "bubbleSort":
                total = value1.ToCharArray();
                char temp;
                for (int write = 0; write < total.Length; write++)
                for (int sor = 0; sor < total.Length - 1; sor++)
                    if (total[sor] > total[sor + 1])
                    {
                        temp = total[sor + 1];
                        total[sor + 1] = total[sor];
                        total[sor] = temp;
                    }
                return Content("Result " + total);
            default:
                return Content("Result 0");                    
        }
开关(calci)
{
案例“bubbleSort”:
总计=值1.ToCharArray();
焦炭温度;
for(int write=0;write总计[sor+1])
{
温度=总温度[sor+1];
总计[sor+1]=总计[sor];
总[sor]=温度;
}
返回内容(“结果”+总计);
违约:
返回内容(“结果0”);
}

可能是错的,但我认为你需要休息一下在案例结尾处。还应包括一个
默认值
大小写。@CapnJack:No;由于
返回值
,无法访问该值。请在开关内添加默认大小写,或在方法末尾添加一个返回值。@SLaks true,谢谢。可能是错误的,但我认为您需要一个
中断在案例结尾处。还应包括一个
默认值
大小写。@CapnJack:No;由于返回值
而无法访问该值。请在开关内添加默认大小写,或在方法末尾添加一个返回值。@SLaks true,谢谢。请参阅
默认值:
此处:请参阅
默认值:
此处: