HiddenInput属性在HiddenInput.cshtml中导致运行时错误

时间:2013-04-17 12:19:52

标签: c# asp.net-mvc linq

更新

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


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

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

  

C:\ PROJ \ Adirondack.search \视图\共享\ EditorTemplates \ HiddenInput.cshtml(9):   错误CS0234:类型或命名空间名称' Linq'不存在于   namespace' System.Data' (你错过了一个程序集引用吗?)

视图模型

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; }

}

Search.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          
         }

    ))

}

1 个答案:

答案 0 :(得分:0)

您在剃须刀视图中使用LINQ表达式。您需要将适当的名称空间导入到视图中才能使用LINQ函数。

使用System.Linq;语句添加到您的视图中。