Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.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# 为控制器设置条件_C#_Html_Asp.net Mvc_Model View Controller - Fatal编程技术网

C# 为控制器设置条件

C# 为控制器设置条件,c#,html,asp.net-mvc,model-view-controller,C#,Html,Asp.net Mvc,Model View Controller,我有这样一个html表单: <div class="form-group"> <labelfor="exampleSelectd">Default Select</label> <select class="form-control" id="Selectio

我有这样一个html表单:

<div class="form-group">                                                                                           
    <labelfor="exampleSelectd">Default Select</label>
    <select class="form-control" id="Selection">
        <option value="Teacher">Teacher</option>
        <option value="Parent">Parent</option>
    </select>
</div>
[HttpPost]
public string Print(FormModel document)
{
    if ( condition ) {
        return WriteFile(...A.docx....);
    }
else {
        return WriteFile( ...B.docx....);
    }                    
}    

public class FormModel 
{    
    public string Selection { get; set; }
    ...
}
如何在控制器上设置条件? 我的意思是当用户选择
Teacher
时,我的控件将
返回WriteFile(…A.docx…)
并且当选择
Parent
时,控制器将
返回WriteFile(…B.docx…)

我的控制器是这样的:

<div class="form-group">                                                                                           
    <labelfor="exampleSelectd">Default Select</label>
    <select class="form-control" id="Selection">
        <option value="Teacher">Teacher</option>
        <option value="Parent">Parent</option>
    </select>
</div>
[HttpPost]
public string Print(FormModel document)
{
    if ( condition ) {
        return WriteFile(...A.docx....);
    }
else {
        return WriteFile( ...B.docx....);
    }                    
}    

public class FormModel 
{    
    public string Selection { get; set; }
    ...
}

FormModel
类被填充并注入到
publicstringprint
方法中。可以使用getter检索model/dto的属性:

class FormController
{
    [HttpPost]
    public string Print(FormModel document)
    {
        if (document.Selection.Equals("Teacher"))
        {
            return WriteFile(...A.docx....);
        }
        else
        {
            return WriteFile(...B.docx....);
        }
    }


}    
public class FormModel {
    public string Selection { get; set; }
}