【发布时间】:2019-08-25 16:43:38
【问题描述】:
我有一个这样的 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>
和一个从上面的表格中获取价值的脚本:
$.post("Home/Print", {
Selection: $("#Selection").val(),
....
})
如何在控制器上设置条件?
I mean when the user chooses <option value="Teacher">Teacher</option>, my Controler will return WriteFile( ...A.docx....); and when chooses <option value="Parent">Parent</option>, the controller will return WriteFile( ...B.docx....);
我的控制器是这样的:
[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; }
...
}
【问题讨论】:
标签: c# html asp.net-mvc model-view-controller