到底如何从 MVC2 复选框获取返回值
我的一张表格上有一个复选框。不幸的是,我似乎无法弄清楚如何从服务器端(我的控制器)的东西中获取价值。在山姆山你怎么做到这一点?看来您必须检查表单元素是否为假?
你如何做到这一点?
添加一些附加信息 if ((formCollection["popID"] != null) && (formCollection["StartDate"] != null) && (formCollection["EndDate"] != null) && (formCollection[ “发送无论如何”]!= null)) { 字符串 popId = formCollection["popID"]; if (formCollection["开始日期"] != "") { startDate = DateTime.Parse(formCollection["StartDate"]); 这
if (formCollection["EndDate"] != "")
{
endDate = DateTime.Parse(formCollection["EndDate"]);
}
Boolean sendAnyway = Boolean.Parse(formCollection["sendAnyway"]);
if (client.ProcessGetABBYPopulation(popId, startDate, endDate, sendAnyway) == false)
{
return PutToQError("Error placing message on Queue");
}
else
{
//return Success("You successfully placed a message on the Queue");
return RedirectToAction("Home", "Home");
}
}
是我的视图(其中有一个复选框)
<%:Html.Label("Reprocess patients already sent during this timeframe?") %>
<%:Html.CheckBox("sendAnyway") %>
更新 2
检查它返回的返回值,“true,false” 这有什么意义呢?
I have a checkbox on one of my forms. And unfortunately, I cant't seem to figure out how to get the value out of the thing on the server side (my controlller). How in sam hill do you do that? It seems like you have to do a check for when the form ellement if not false?
How do you do this?
Adding some addition information
if ((formCollection["popID"] != null) && (formCollection["StartDate"] != null) && (formCollection["EndDate"] != null) && (formCollection["sendAnyway"] != null))
{
string popId = formCollection["popID"];
if (formCollection["StartDate"] != "")
{
startDate = DateTime.Parse(formCollection["StartDate"]);
}
if (formCollection["EndDate"] != "")
{
endDate = DateTime.Parse(formCollection["EndDate"]);
}
Boolean sendAnyway = Boolean.Parse(formCollection["sendAnyway"]);
if (client.ProcessGetABBYPopulation(popId, startDate, endDate, sendAnyway) == false)
{
return PutToQError("Error placing message on Queue");
}
else
{
//return Success("You successfully placed a message on the Queue");
return RedirectToAction("Home", "Home");
}
}
Here is my view (where I have a checkbox)
<%:Html.Label("Reprocess patients already sent during this timeframe?") %>
<%:Html.CheckBox("sendAnyway") %>
Update 2
Checking my return value it returns, "true,false"
what kind of sense does that make?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不使用强类型视图模型,则可能会执行以下操作:
在这种情况下,您可以在将其 POST 到服务器时访问它,如下所示:
如果您使用强类型视图模型,它可以以相同的方式使用:
然后像这样访问:
If you're not using a strongly typed view model, you're probably doing something like this:
In which case, you can access it when you POST it to your server like so:
If you're using a strongly typed view model, it's available the same way:
And then accessed like: