Closed learner291 closed 4 years ago
you might need references in your _ViewImports
@using FormFactory @using FormFactory.Attributes
Thank you it has worked on my demo application. However, we are unable to use FormFactory as it seems that is not compatible with .net core 3 (https://github.com/mcintyre321/FormFactory/issues/89) which is what we are using in our production system, that is unfortunate as I was looking forward to exploring and using FormFactory.
I am new to FormFactory and also learning MVC at the same time. I am trying to create a dynamic form using PropertyVm. I was able to create form when I use following code in Index.cshtml view.
`@{
Next step I am trying to do is pass above variable from Controller, once that is done then I will try to get data from the database to build the model. The code that I have in my controller and view is displayed below.
` public IActionResult Index() { PropertyVm[] formModel = new[] { new PropertyVm(typeof(DateTime) , "date") { DisplayName = "Your birthday", NotOptional =true, GetCustomAttributes = () => new object[] { new DateAttribute() } }, new PropertyVm(typeof(string) , "textmessage") { DisplayName = "Type a message:", NotOptional =false, GetCustomAttributes = () => new object[] { new MultilineTextAttribute(), new DisplayAttribute() { Prompt = "placeholder??" }, new System.ComponentModel.DescriptionAttribute("Type anything here.") }, }, new PropertyVm(typeof(string) , "number") { DisplayName = "Select a number", NotOptional =false, Choices = new List() {"one","two","three","four" },
},
new PropertyVm(typeof(string), "username")
{
DisplayName = "Username",
NotOptional = true,
Suggestions = new List() { "holy poo" },
},
new PropertyVm(typeof(string), "password")
{
DisplayName = "Password",
NotOptional = true,
GetCustomAttributes = () => new object[]{ new PasswordAttribute() }
},
new PropertyVm(typeof(string), "os")
{
DisplayName = "Operating System",
NotOptional = true,
Choices = new List() {"OSX", "IOS", "Windows", "Android"},
Value = "Windows", //Preselect windows
GetCustomAttributes = () => new object[] {new RadioAttribute(), new System.ComponentModel.DescriptionAttribute("Make a choice above.") }
},
new PropertyVm(typeof(bool), "check")
{
DisplayName = "Check if happy",
NotOptional = true,
Value = false, //Preselect false (unchecked)
GetCustomAttributes = () => new object[] {new FormFactory.Attributes.LabelOnRightAttribute() } // right label
},
new PropertyVm(typeof(bool), "check2")
{
DisplayName = "Check if sad",
Value = false, //Preselect false (unchecked)
NotOptional =true
In my view
` @{ var formModel = ViewBag.Message;
`
However I am now getting following error. Can someone please let me know what I am doing incorrectly?
An unhandled exception occurred while processing the request. RuntimeBinderException: 'System.Array' does not contain a definition for 'Render' CallSite.Target(Closure , CallSite , object , IHtmlHelper