I have a page with a blocklist. One of the blocklist items is a form with parameters that vary depending on its position in the blocklist. parameters are properties of the element (textstring, int). The submit of the form is associated with an action of a surface controller.
How do I retrieve only the model of the element and not the one of the whole page in the controller?
Based on the information provided, it seems like you have a page with a blocklist, and within the blocklist, there is a form with parameters that vary based on its position. You want to retrieve only the model of the element associated with the form, not the entire page model, in the controller.
To achieve this, you can use the "BindProperty" attribute in your Surface Controller to selectively bind the model for the specific element Pay My Doctor associated with the form.
There's how you can do it:
Create a model class for the element's properties. For example:
public class ElementModel
{
public string TextString { get; set; }
public int IntValue { get; set; }
}
In your Surface Controller, define a property with the same model class for the element:
public class YourSurfaceController : SurfaceController
{
// Other actions and code
[BindProperty]
public ElementModel Element { get; set; }
// Your action method for handling the form submission
public IActionResult SubmitForm()
{
// Access the properties of the specific element only using the "Element" property
// For example, you can access TextString and IntValue like this:
string textString = Element.TextString;
int intValue = Element.IntValue;
// Your processing logic here
return View(); // Or return a Redirect or any other result as needed
}
Thank you Gregory,
I tried but it doesn't work for me. The controller still uses the page model and not the partial view model.
The form is created using BeginUmbracoForm. Maybe it depends on that?
SurfaceController and blocklist model data
I have a page with a blocklist. One of the blocklist items is a form with parameters that vary depending on its position in the blocklist. parameters are properties of the element (textstring, int). The submit of the form is associated with an action of a surface controller. How do I retrieve only the model of the element and not the one of the whole page in the controller?
Thanks
Giampaolo
Based on the information provided, it seems like you have a page with a blocklist, and within the blocklist, there is a form with parameters that vary based on its position. You want to retrieve only the model of the element associated with the form, not the entire page model, in the controller.
To achieve this, you can use the "BindProperty" attribute in your Surface Controller to selectively bind the model for the specific element Pay My Doctor associated with the form. There's how you can do it:
Create a model class for the element's properties. For example:
public class ElementModel { public string TextString { get; set; } public int IntValue { get; set; } }
In your Surface Controller, define a property with the same model class for the element:
public class YourSurfaceController : SurfaceController { // Other actions and code
}
Thank you Gregory, I tried but it doesn't work for me. The controller still uses the page model and not the partial view model. The form is created using BeginUmbracoForm. Maybe it depends on that?
is working on a reply...