The expression tree may not contain a dynamic operation, but that does not tell me where

I have a problem when I receive a message:

\ OrderGas.cshtml (24): error CS1963: expression tree may not contain dynamic operation "}

Here is my code for my web form:

@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 current percentage in your tank.</label>
                @Html.ValidationMessageFor(m => m.TankPercent)
              </div>             

              <br/>

              <div class="editor-field">
                @Html.CheckBoxFor(x => x.IsFill)
                @Html.LabelFor(m => m.IsFill)
                <label class="SmallBluelabel">Would you like us to fill your tank?</label>
                @Html.ValidationMessageFor(m => m.IsFill)
              </div>

              <div class="editor-label">
                <b> - OR - </b>
              </div>

              @if (!string.IsNullOrWhiteSpace(ViewBag.AlternateGasMessage))
              {
                <fieldset class="pleasenote">
                  <legend>@ViewBag.AlternateGasMessageHeader</legend>
                  <label class="warningLabel">@ViewBag.AlternateGasMessage</label>                  
                </fieldset>
              }

              <div class="editor-label">
                @Html.LabelFor(m => m.Amount)
              </div>

              <div class="editor-field">
                @Html.TextBoxFor(m => m.Amount, new { @class = "GenericSmallTextBox" })
                <label class="SmallBluelabel">Or request a specific amount in the tank?</label>


                @if (ViewBag.MinimumGasMessage != null)
                {
                  <div>
                    <label class="SmallBluelabel">@ViewBag.MinimumGasMessage</label>
                  </div>
                }

                @Html.ValidationMessageFor(m => m.Amount)
              </div>             

              <div class="editor-label">
                @Html.LabelFor(m => m.ContactNumber)
              </div>
              <div class="editor-field">
                @Html.TextBoxFor(m => m.ContactNumber, new { @class = "GenericTextBox" })
                @Html.ValidationMessageFor(m => m.ContactNumber)                   
              </div>

              <div class="editor-label">
                @Html.LabelFor(m => m.Message)
              </div>
              <div class="editor-field">
                @Html.EditorFor(x => x.Message)            
              </div>

              <div>
                <input type="submit" value="Submit" class="typicalbutton"/>
              </div>

            </fieldset>

          </div>
        }

Here is the class that invokes the web form:

public ActionResult OrderGas()
{
  var control = Logging.StartLog();

  try
  {
    Logging.WriteLog("Starting OrderGas");

    var svc = new SubService();
    var orderGasModel = new OrderGasModel();

    orderGasModel.ContactNumber = svc.GetCustomerPhoneNumber(SessionHelper.TokenId, SessionHelper.CurrentAccountGuid);
    Logging.WriteLog(string.Format("orderGasModel.ContactNumber: {0}", orderGasModel.ContactNumber));

    if (SessionHelper.ShowPaymentOptions)
    {
      SessionHelper.PaymentMethods = GetPaymentMethods2();
    }
    if (SessionHelper.MinimumGasOrderAmount > 0)
    {
      var msg = string.Format("Minimum gas order is {0} gallons.", SessionHelper.MinimumGasOrderAmount);
      Logging.WriteLog(msg);
      ViewBag.MinimumGasMessage = msg;
    }

    var gasordermsg = svc.GetAlternateGasOrderMessage(SessionHelper.TokenId);
    ViewBag.AlternateGasMessageHeader = gasordermsg.Item1;
    ViewBag.AlternateGasMessage = gasordermsg.Item2;
    ViewBag.Account = string.Format("{0}-{1}", SessionHelper.CurrentBranchNumber.ToBranchString(),
      SessionHelper.CurrentAccountNumber.ToAccountString());

    return View(orderGasModel);
  }
  catch (Exception ex)
  {
    Logging.WriteException(ex);
    Logging.WriteLog(ex.Message);
    return View("Error");
  }
  finally
  {
    Logging.WriteLog(control, "End OrderGas");
  }
}

I compared this to my story to see what I changed, and I don’t understand why it is no longer working. When I send debugging to my PaymentMethods methods, it throws an exception before it gets there.

I tried to comment on the components of cshmtl, and I can not get a clear answer about how much of it causes an error.

I'm at a loss ... does anyone see what I'm doing wrong?

+4
2

HTML @model. , , , .

cshtml @model OrderGasModel

+13

@model cshtml, , "@model" . :

@model List<MyDataStructure>

, , , ( ".ToList()" ). :

@model ListMyDataStructure

public class ListMyDataStructure
{
    public List<MyDataStructure> ListOfData { get; set; }
}
+1

All Articles