using (Html.BeginUmbracoForm<UserProfileSurfaceController>("StoreData", new { @TopicPageId = test }))
{
<input type="submit" id="submitAnswar" value="@umbracoHelper.GetDictionaryValue("Next Question")">
}
i tried with some Javascript / ajax and i was able to pass it to a ApiController. but since this is stainless , i need it in a surfacecontroller.
really hope someone out there have a magic spell that will work.
I find whenever i try to pass the Data around like that, my model is always null, when it reach the controller.
I'm using a UaaS setup so have models / controls in the core.project and a web for my view. not sure if this is having an impact on why my model in the control is null. but found that when using
using (Html.BeginUmbracoForm<UserProfileSurfaceController>("StoreData", new { @TopicPageId = test }))
{
<input type="range" name="sliderName" id="sliderValue" min="1" max="100" value="50" class="slider">
<input type="submit" id="submitAnswar" value="@umbracoHelper.GetDictionaryValue("Next Question")">
}
i'm able to get the to my controller test is just a int = 3000 and i can read that just find in the controller
so if i'm able to pass the value from my slider input to the int test i should work but i'm stuck at that point
public class UserProfileModel
{
public int TopicPageId { get; set; }
public int UserId { get; set; }
public int UserResult { get; set; }
public int NumberOfQuestions { get; set; }
}
and the controller itself
using System.Web.Mvc;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Mvc;
using conservative.Core.Models;
namespace conservative.Core.Controllers
{
public class UserProfileSurfaceController : SurfaceController
{
UserProfileModel vm = new UserProfileModel();
[HttpPost]
public ActionResult StoreData(int? UserResult)
{
if (UserResult != null)
{
int test2 = vm.UserResult;
test2 += (int)TopicPageId;
vm.UserResult += test2;
}
return RedirectToCurrentUmbracoPage();
}
}
When i debug my controller the UserResult is always null so i cannot update the VM with the new values. which i need for later use.
In other words i need to pull out the value from input ranged. store it in away so i can send it to the surfacecontroller.
public ActionResult StoreData(UserProfileModel model)
{
}
Then access the values from your model. You can pass primitive types to a controller as it doesn't work with the model binding - you need to pass a class with the properties you want to bind. Your input fields need to have the names match the property names in your class.
int test = 3000;
using (Html.BeginUmbracoForm<UserProfileSurfaceController>("StoreData", new { UserResult = test }))
{
<input type="submit" id="submitAnswar" value="@umbracoHelper.GetDictionaryValue("Next Question")">}
and then using
public ActionResult StoreData(UserProfileModel model){}
I can store it in the model, but i still have no way of getting the data from the ranged input to the controller.
Get value from input
Hey all
Hope someone you code wizards can help me.
I need to pass some value from my user to a controller.
and then i need a way to pass it as a value in
i tried with some Javascript / ajax and i was able to pass it to a ApiController. but since this is stainless , i need it in a surfacecontroller.
really hope someone out there have a magic spell that will work.
You need your range input to be within the form and it to have a name - it's this what identifies what the value is eg.
Look at this tutorial for Surface Controller forms:
https://our.umbraco.com/Documentation/Reference/Templating/Mvc/Forms/tutorial-partial-views
I find whenever i try to pass the Data around like that, my model is always null, when it reach the controller.
I'm using a UaaS setup so have models / controls in the core.project and a web for my view. not sure if this is having an impact on why my model in the control is null. but found that when using
i'm able to get the to my controller test is just a int = 3000 and i can read that just find in the controller
so if i'm able to pass the value from my slider input to the int test i should work but i'm stuck at that point
Strange. Can you create a model class like this:
Then have that as the value to your controller. Then I can suggest is attaching a debugger to the controller and seeing what data is sent.
Can you post the code for your UserProfileSurfaceController controller?
the SurfaceController is using this model
and the controller itself
When i debug my controller the UserResult is always null so i cannot update the VM with the new values. which i need for later use.
In other words i need to pull out the value from input ranged. store it in away so i can send it to the surfacecontroller.
Try changing it to this:
Then access the values from your model. You can pass primitive types to a controller as it doesn't work with the model binding - you need to pass a class with the properties you want to bind. Your input fields need to have the names match the property names in your class.
so fare passing the data from the view like this
and then using
I can store it in the model, but i still have no way of getting the data from the ranged input to the controller.
On your
UserProfileModel
you need to have a property calledSliderName
or whatever name you have given to your slider input.This is how the binding works.
cheers it got the value from the slider in the model. I'll have to read up on the binding part when i get some free time thanks for the insight
is working on a reply...