Skip to content

Instantly share code, notes, and snippets.

@nonnb
Created December 19, 2014 05:43
Show Gist options
  • Save nonnb/89b8c93870ca3ae6536a to your computer and use it in GitHub Desktop.
Save nonnb/89b8c93870ca3ae6536a to your computer and use it in GitHub Desktop.
namespace WebApplication4.Controllers
{
// Some POCO's
public class DesignParam
{
public string ParamID { get; set; }
}
public class Foo
{
public int ID { get; set; }
public string Title { get; set; }
public DesignParam[] DesignParams { get; set; }
}
public class HomeController : Controller
{
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
var model = new Foo {ID = 1234, Title = "FOO",
DesignParams = new []
{
new DesignParam { ParamID = "1234" } // Set the default value ON the actual model
}};
return View(model);
}
}
}
@model WebApplication4.Controllers.Foo
<div class="editor-field">
@Html.Editor("Title", // This is a property of Model - the value is reflected off the property
new
{
htmlAttributes = new
{
@class = "form-control text-right",
@type = "text",
id = "_" + 54,
data_uomid = 9832,
data_measureid = 12312
}
})
@Html.Editor("DesignParams[0].ParamID", // This doesn't work.
new
{
htmlAttributes = new
{
@class = "form-control text-right",
@type = "text",
id = "_" + 54,
data_uomid = 9832,
data_measureid = 12312
}
})
@Html.EditorFor(m => m.DesignParams[0].ParamID, // This works, and value is reflected off the property
new
{
htmlAttributes = new
{
@class = "form-control text-right",
@type = "text",
id = "_" + 54,
data_uomid = 9832,
data_measureid = 12312
}
})
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment