Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7950021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:08:26+00:00 2026-06-04T02:08:26+00:00

In my view file I current have the following code: @if ((Model.CustomerOrderTrackings != null)

  • 0

In my view file I current have the following code:

    @if ((Model.CustomerOrderTrackings != null) && (Model.CustomerOrderTrackings.Count > 0)) {
        for (int i = 0; i < Model.CustomerOrderTrackings.Count; i++) {
            @Html.EditorFor(m => m.CustomerOrderTrackings[i])
        }
    } else {
        @*The problem is here*@
        @Html.EditorFor(m => new CustomerOrderTracking())
    }

Then, my editor template looks like this:

@model Models.CustomerOrderTracking

<tr class="gridrow">
    <td class="carrierName">
        @Html.HiddenFor(m => m.Id, new { id = "" })
        @Html.HiddenFor(m => m.ShipperId, new { id = "", @class = "trackingShipperId" })
        @Html.DropDownListFor(m => m.CarrierName, ViewExtensions.ToFriendlySelectList<CustomerOrderTracking.CarrierNames>(Model.CarrierName), new { id = "" })
    </td>
    <td class="service">@Html.DropDownListFor(m => m.ShippingType, ViewExtensions.ToFriendlySelectList<CustomerOrderTracking.ShippingTypes>(Model.ShippingType), new { id = "" })</td>
    <td class="trackingNumber">@Html.TextBoxFor(m => m.ShippingTrackingNumber, new { @class = "trackingInput", id = "" }) <a href="" target="_blank" class="icon track"></a></td>
    <td class="shippingCost">
        @Html.TextBoxFor(m => m.ShippingCost, new { @class = "shippingInput", id = "" })
        <div onclick="Operations.Orders.DeleteTrackingRow(this)" class="icon delete deleteTracking" title="Delete this shipment?"></div>
    </td>
</tr>

What I’m trying to do is add a default row to this table in the event that there aren’t currently any items attached to the object. The new instance of the object isn’t working, since that results in the following error: Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.

I could hand-code the inputs, but then my code is rather sloppy since I’d be using hand-coded inputs and then auto-generated inputs from the ASP.NET MVC extensions.

Is there a way that I can pass a default instance of the object to my editor template?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:08:27+00:00Added an answer on June 4, 2026 at 2:08 am

    The way I see it, in an MVC framework, the way to accomplish what you want is to detect your requirement in the controller and adjust the model as necessary before it reaches the view. The other answer, that is 99% not the religiously property way to do it, is to have logic in your view (ew!).

    public ActionResult SomeAction()
    {
    
      if (model.CustomerOrderTrackings == null 
          || model.CustomerOrderTrackings.Count > 0) 
      {
        // Do Something with model
      }
    
      this.View(model)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following evaluation which works great: In my listings/detail.html.erb view <% if
I want to create a generic html table to excel file view that can
In my xib file I have some View. And I have PainView class (UIView).
I have created XML file,but I can't view it/output it.I know there is no
I have a controller called votes_controller.rb . In that file there is the following
I current have the following attribute decorating one of the action method. [Authorize(Roles =
I have declared the following in my .h file: Annotation *annoForMoreDetails . However when
I have the following acceptance criteria for creating a pdf file from my asp.net
I have a view file(.cshtml) with this C# block in top of file: @{
I have the following code written, <?php require_once products.php; $test = new Products; $array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.