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 7545529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:57:15+00:00 2026-05-30T08:57:15+00:00

I’m reasonably new to Spark, and I’m finding it difficult to find resources for

  • 0

I’m reasonably new to Spark, and I’m finding it difficult to find resources for what are generally simple questions, whereas I can often find the answers in Razor. Though mostly there is a good cross over between the two, I’m currently unable to work out what I’m doing wrong with this Razor-Spark translation.

The situation is that I have a model with a list of objects on it (and some other properties). I want to be able to display the list in a table and to be able to edit a couple of the properties of the model within the list. Reading around, the best way to do this is to set up an editor template and then to use an Html.EditorFor with the whole list. I tried this and when I post the form back to the controller, I get a null as the posted list so I’ve stripped it down to a set of test code that encapsulates what I want to do (a readonly int property an editable checkbox) and set up a test controller/views to reproduce the problem.

Controller:

public class TestController : Controller
{
    public ActionResult ListTest()
    {
        var model = new List<TestModel>
                        {
                            new TestModel {Id = 1, Checked = true},
                            new TestModel {Id = 2, Checked = true},
                            new TestModel {Id = 3, Checked = false}
                        };

        return View(model);
    }

    [HttpPost]
    public ActionResult ListTest(List<TestModel> model)
    {
        return View(model);
    }
}

Working Razor view:

@model IList<TestModel>

@using (Html.BeginForm("ListTest", "Test", FormMethod.Post))
{
  <table style="border: 1px solid">
    @Html.EditorFor(x => x)    
  </table>
  <input type="submit" value="Clicky!" />
}

Working Razor editor template:

@model TestModel

<tr>
  <td>
    @Html.DisplayFor(x => x.Id)
    @Html.HiddenFor(x => x.Id)
  </td>
  <td>@Html.CheckBoxFor(x => x.Checked)</td>
</tr>

Attempted Spark view:

<viewdata model="IList<TestModel>" />

<content name="main">

  <div id="main">

    <form action='' id='testform' method='post'>
      <table>
        <tr each="var item in Model">
          ${Html.EditorFor(x => item, "TestModel")}
        </tr>    
      </table>
      <input type="submit" value="Clicky!" />
    </form>

  </div>

</content>

Attempted Spark editor template:

<viewdata model="TestModel" />

  <td>
    ${Model.Id}
    ${Html.HiddenFor(x => x.Id)}
  </td>
  <td>${Html.CheckBoxFor(x => x.Checked)}</td>

Unfortunately, I get an error whenever I try to set the Spark up in the same way as the Razor engine and just pass the list to the single object editor, saying that the types don’t match and it is expecting single object rather than a list, so I’ve had to enumerate the list before passing it to the editor template, which I think is causing the problem.

I’ve been looking around but can’t find a solution for this at the moment. I’d like to use Spark for this rather than have to craft just these views in Razor, but I can’t figure out how so far. The one area I’m not yet clear on is bindings within Spark and whether they might give me what I need, but any help would be greatly appreciated.

Cheers

  • 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-05-30T08:57:16+00:00Added an answer on May 30, 2026 at 8:57 am

    You wrote a foreach loop in your Spark view. Don’t write such loops with editor templates. You don’t need em:

    <viewdata model="IList<TestModel>" />
    
    <content name="main">
      <div id="main">
        <form action='' id='testform' method='post'>
          <table>
              ${Html.EditorForModel()}
          </table>
          <input type="submit" value="Clicky!" />
        </form>
      </div>
    </content>
    

    and in your template:

    <viewdata model="TestModel" />
    <tr>
      <td>
        ${Model.Id}
        ${Html.HiddenFor(x => x.Id)}
      </td>
      <td>${Html.CheckBoxFor(x => x.Checked)}</td>
    </tr>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm making a simple page using Google Maps API 3. My first. One marker

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.