0

I am submiiting a form from view which contains input field with specific data attribute

<form>
<input type="text" data-user="001" name="mytext" />
</form>

this from is submitted to a controller

[HttpPost]
        public ActionResult Settings(FormCollection formValues)
        {
//here i can access input control's value by its name like
string user= formValues["mytext"];
}

but how i can get value of data-user attribute in controller?

3
  • 2
    You cannot. A form only submits name/value pairs corresponding to the name and value attributes of form controls. Commented Dec 21, 2015 at 10:09
  • 2
    You can do it using javascript. You should add hidden inputs to your form on submit. Commented Dec 21, 2015 at 10:19
  • you have to use hidden field data- attributes will not be posted in form Commented Dec 21, 2015 at 10:26

1 Answer 1

0

I do not think you can do it. You can access session variable from controller like this, however:

string strsetting1 = (string)HttpContext.Session["setting1"];

In your Global.asax.cs:

protected void session_start()
{
    Session["setting1"] = "Y";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.