我有一个必填字段,字符串属性{get; 在一个类中设置}并希望在剃刀中设置它的值.是否有类似以下内容?
@model.attribute = "whatever'
Run Code Online (Sandbox Code Playgroud) 我收到此错误:
错误CS1973:'System.Web.Mvc.HtmlHelper'没有名为'Partial'的适用方法,但似乎有一个名称的扩展方法.无法动态分派扩展方法.考虑转换动态参数或调用扩展方法而不使用扩展方法语法."}
从我在这里读到的Razor View Engine:表达式树可能不包含动态操作,因为它使用的是我正在使用Session的viewbag(?).
这是我的网络表单:
@using SuburbanCustPortal.MiscClasses
@{
ViewBag.Title = "Account Screen";
}
<h2>AccountScreen</h2>
<div class="leftdiv">
<fieldset>
<legend>Customer Info</legend>
@Html.Partial("CustomerInfo")
</fieldset>
<fieldset>
<legend>Delivery Address</legend>
@Html.Partial("DeliveryAddress")
</fieldset>
<fieldset>
<legend>Delivery Info</legend>
@Html.Partial("DeliveryInfo")
</fieldset>
</div>
<div class="rightdiv">
<fieldset>
<legend>Balance</legend>
@Html.Partial("AccountBalance")
</fieldset>
@if (SessionHelper.ShowPaymentOptions || SessionHelper.ShowHistory)
{
<fieldset>
<legend>Account Options</legend>
<br/>
@using (Html.BeginForm("AccountScreenButton", "Customer", FormMethod.Post))
{
<div class="sidebysidebuttons">
<div class="box">
@if (SessionHelper.ShowHistory && SessionHelper.ShowAccountScreenPaymentButton)
{
<button class="sidebysidebutton1" name="options" value="payment">Make a Payment</button>
<button class="sidebysidebutton2" name="options" value="activity">Display Activity</button>
}
else
{
if (SessionHelper.ShowAccountScreenPaymentButton) …
Run Code Online (Sandbox Code Playgroud) 我在这里找到了类似的问题: Razor View Engine:表达式树可能不包含动态操作
但我尝试过这些解决方案并没有解决我的问题.我有一个控制器,具有以下内容:
public ActionResult CreateOrganization(Guid parentOrganizationId)
{
Organization organization = new Organization();
return View(organization);
}
Run Code Online (Sandbox Code Playgroud)
该视图具有以下内容:
@using Project.Data
@Model Project.Data.Organization
@{
ViewBag.Title = "Create new Organization";
}
<hgroup class="title">
<h1>@ViewBag.Title.</h1>
<h2>Use the form below to create a new Organization.</h2>
</hgroup>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
@using (Html.BeginForm((string)ViewBag.FormAction, "Organization"))
{
<fieldset>
<legend>Create Organization</legend>
<ol>
<li>
@Html.LabelFor(m=> m.Name)
@Html.TextBoxFor(m=> m.Name);
@Html.ValidationMessageFor(m=> m.Name)
</li>
</ol>
<input type="submit" value="Register" />
</fieldset>
}
Run Code Online (Sandbox Code Playgroud)
这是明确指定模型(如另一篇文章中所建议的).但是我仍然收到'表达式树可能不包含动态操作'错误.我在某个地方犯过一个愚蠢的错误吗?
我有一个问题,我收到的消息:
\ OrderGas.cshtml(24):错误CS1963:表达式树可能不包含动态操作"}
这是我的网络表单的代码:
@using SuburbanCustPortal.MiscClasses
@{
ViewBag.Title = "Order Gas";
}
<h2>Order Gas</h2>
@using (Html.BeginForm("OrderGasSuccess", "GasOrder", FormMethod.Post))
{
@Html.ValidationSummary(true, "Submit was unsuccessful. Please correct the errors and try again.")
<div>
<fieldset>
<legend>Account Information - all fields required</legend>
<div class="highlightedtext">
@ViewBag.Account
</div>
@if (SessionHelper.ShowPaymentOptions)
{
<div class="editor-label">
@Html.LabelFor(m => m.PaymentMethod)
</div>
<div class="editor-field">
@Html.DropDownListFor(x => x.PaymentMethod, SessionHelper.PaymentMethods)
</div>
}
<div class="editor-label">
@Html.LabelFor(m => m.TankPercent)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.TankPercent, new { @class = "GenericSmallTextBox" })
<label class="SmallBluelabel">Please enter the …
Run Code Online (Sandbox Code Playgroud)