use*_*767 2 c# asp.net-mvc entity-framework-4 asp.net-mvc-3
为什么将字符串转换/解析为 int 返回 0/零?
在调试时,使用断点,我可以看到“3”作为字符串值发布到浏览操作,但是当我如上所述转换为 int 时,该值将转换为 int 类型的 0 值。
//
// GET: /Event/Browse
public ActionResult Browse(string category)
{
int id = Convert.ToInt32(category);
// Retrieve Category and its Associated Events from database
var categoryModel = storeDB.Categories.Include("Events").Single(g => g.CategoryId == id);
return View(categoryModel);
}
Run Code Online (Sandbox Code Playgroud)
查看下图以更好地理解:

另一张图片 -categoryModel 在 LINQ 查询上获取 null。

| 归档时间: |
|
| 查看次数: |
4279 次 |
| 最近记录: |