1

更新

所以,我一直在看错误的文件。我的项目有两个 HiddenInput.cshtml 文件,一个在 displayTemplate 文件夹中,一个在 EditorTemplates 中。我的大脑没有建立联系,我正在查看两个不同的文件夹。


因此,将 hiddenInput 属性添加到我的 ViewModel 中的属性时,这似乎是一个奇怪的错误...

我对原因的猜测是因为我的 ViewModels、Controllers 和 Models 在 3 个单独的项目中。但是,当我尝试调试此问题时,我确保在所有三个中都引用了 System.Data.Linq。

c:\proj\Adirondack.search\Views\Shared\EditorTemplates\HiddenInput.cshtml(9):错误 CS0234:命名空间“System.Data”中不存在类型或命名空间名称“Linq”(您是否缺少程序集参考?)

视图模型

public class BasicSearchViewModel 
{
    public BasicSearchViewModel()
    {
        SalesFrom = new DateTime(1974, 1, 1);
        SalesTo = DateTime.Today;
    }

    [Display(Name = "Owner", ShortName = "Owner", Prompt = "Enter Owner"), DataType(DataType.Text)] 
    public string OwnerName { get; set; }
    [Display(Name = "Account Number", ShortName = "Strap", Prompt = "Enter Account Number"), DataType(DataType.Text)] 
    public string STRAP { get; set; }

    [Display(Name = "Address", ShortName = "Addr.", Prompt = "Enter full address"), DataType(DataType.Text)] 
    public string Address { get; set; }
    //public bool HasPool { get; set; }


    public string Location { get; set; }

    public string ZipCode { get; set; }


    public bool Pool { get; set; }

    public bool Tennis { get; set; }

    public bool Dock { get; set; }

    public bool SeaWall { get; set; }


    [Display(Name = "Sales From")]
    [Range(typeof(DateTime),"1/1/1974","12/31/2050")]        
    public DateTime SalesFrom { get; set; }

    [Display(Name="Sales To")]
    [Range(typeof(DateTime), "1/1/1974", "12/31/2050")]
    public DateTime SalesTo { get; set; }


    public int? SaleAmountFrom { get; set; }
    public int? SaleAmountTo { get; set; }


    public bool VacantLand { get; set; }

    [ScaffoldColumn(false)]
    public PagedList<ParcelResultItemViewModel> SearchResults { get; set; }

    [HiddenInput]
    public int? page { get; set; }

}

搜索.cshtml

@using Search.Helpers;
@using Search.Components.Html.ViewModels;
@using PagedList.Mvc;


@model BasicSearchViewModel

@{
    ViewBag.Title = "Search";

}

@Html.ActionLink("Advanced", "AdvancedSearch")
@Html.ActionLink("Tangible", "Search", "Tangible")

@using (Html.BeginForm("Search", "Parcel",  FormMethod.Get, new { id = "searchForm" }))
{

<div>@Html.ValidationMessageFor(x => x)</div>

    @Html.EditorFor(m => m)
     <input type="submit" value="Refine" />




        <h2>Results</h2>
<strong>Showing the first @Model.SearchResults.TotalItemCount of  @ViewData["count"] results found </strong>

<table>
<tr>
<th>STRAP</th>
<th>SITUS</th>
<th>PROPERTY USE</th>
<th></th>
</tr>
@foreach (var item in Model.SearchResults)
{
    <tr>
        <td>
            @Html.DisplayFor(x => item.STRAP) 
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.SITUS)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.SUBDIVISION_PROPERTY_USE)
        </td>
        <td rowspan="2">
            @Html.ActionLink("Show Details", "Details", new { id = item.STRAP })
        </td>
    </tr>
    <tr>
    <td colspan="3">
    @foreach (var owner in item.OWNERS.Take(2).OrderBy(x => x.LN_NUM))
    {
       @owner.NAME<br /> 
    }
    </td>
    </tr>
}

</table>

<pre>
@HttpUtility.ParseQueryString(Model.AsQueryString())
</pre>   

@Html.PagedListPager(Model.SearchResults, page => Url.Action("search", 
    new {Page = page,   
        owner = Model.OwnerName,
        AccountNumber = Model.STRAP,
        Address = Model.Address,
        Location = Model.Location,
        ZipCode = Model.ZipCode,
        Pool = Model.Pool,
        Tennis = Model.Tennis,
        Dock = Model.Dock,
        SeaWall = Model.SeaWall,
        SalesFrom = Model.SalesFrom,
        SalesTo = Model.SalesTo,
        SaleAmountFrom = Model.SaleAmountFrom,
        SaleAmountTo = Model.SaleAmountTo,
        VacantLand = Model.VacantLand          
         }

    ))

}
4

1 回答 1

0

您正在 razoe 视图中使用LINQ表达式。您需要将正确的命名空间导入到您的视图中才能使用 LINQ 函数。

将 usingSystem.Linq;语句添加到您的视图中。

于 2013-04-17T12:31:18.553 回答