可能重复:
如何从MS Access数据库中获取随机记录
在我的项目中,我经历了一个场景,我必须从MS Access表中随机检索记录.我应该使用什么查询来检索随机库中的记录?
我正在开发一个Asp.net MVC应用程序,并遇到了一个场景,我必须在两列中显示内容(即并排)我googled并在这里遇到了一个解决方案.我试过但徒劳无功.我试过这种方式
@model IEnumerable<MvcApplication1.tblTest>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
<table>
<tr>
<th>
testId
</th>
<th>
testName
</th>
<th>
testDescription
</th>
<th></th>
</tr>
@for (var i = 0; i < Model.Count(); i+=2 )
{
<tr>
<td>
@Model[i].testId
</td>
</tr>
}
</table>
Run Code Online (Sandbox Code Playgroud)
但是我收到了编译错误 - 编译错误
描述:编译服务此请求所需的资源时发生错误.请查看以下特定错误详细信息并相应地修改源代码.
Compiler Error Message: CS0021: Cannot apply indexing with [] to an expression of type
'System.Collections.Generic.IEnumerable<MvcApplication1.tblTest>'
Source Error:
Line 27: <tr>
Line 28: <td>
Line 29: @Model[i].testId
Line 30: </td>
Line 31:
Run Code Online (Sandbox Code Playgroud)
有谁可以帮我解决这个问题?
我正在尝试将两个模型(tblCategories 和 tblProducts)组合成一个模型并将其传递给视图。但是没办法。
作为主模型的tblCategory.cs具有以下数据
namespace ScaffoldCreate.Models
{
using System;
using System.Collections.Generic;
public partial class tblCategory
{
public int CategoryId { get; set; }
public string Name { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
tblProduct.cs
public partial class tblProduct
{
public int ProductId { get; set; }
public int ProductName { get; set; }
public int CategoryId { get; set; }
public int SubCategoryId { get; set; }
public string ProductDescription { get; set; }
public string StockStatus { …Run Code Online (Sandbox Code Playgroud) 我试图将隐藏的字段值从一个控制器中的视图传递到另一个控制器.我尝试了下面的代码:
@using (Html.BeginForm("AddToCart","Cart"))
{
<input type="hidden" id="testName" value= @model[0].tblProd[0].ProductName />
}
Run Code Online (Sandbox Code Playgroud)
并尝试在名为"Cart"的控制器中检索该代码,如下所示:
public ViewResult AddToCart(FormCollection collection1)
{
string prodName = Request["testName"];
return View();
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用.有人可以协助我解决这个问题.
asp.net-mvc ×3
razor ×3
view ×2
foreach ×1
forms ×1
hidden-field ×1
indexing ×1
model ×1
ms-access ×1
random ×1