0

I hope you can help me with this.

I need to do the following but I dont know if its possible.

On my view I have a function that receives one parameter. That value already exists in a texbox field but I don't know how to send it to my function.

 <% Permissions TV = new Permissions();  %>            
 <%: Html.TreeViewAsUnorderedList(TV.GetPermissionsItems((int?)document.getElementById('txtPerfil').value  ))%>  

 <%: Html.TextBox("txtPerfil","" , new { disabled = "true", style = "width:20px", id = "txtPerfil"  })%>

Regards,

2 Answers 2

2

Ok, you have a value in a Textbox which you want to send to server side (function/action).

You should have a event, on which you can send this value to your action method. Events can be any simple javascript event like, onBlur, onClick etc... that I leave on to you to decide.

Now sending value to function. Here if you dont want a post back to happen, which I assume you do, you need to make an ajax/json call to your action and pass the value here.

Sample Code : taken from this article

Js/Jquery Code

var url = '@Url.Action("GetData")';
$.ajax({
url: url,
type: 'GET',
cache: false,
data: { value: strId},

success: function (result) {
$('#result).html(result);
  alert(result.foo + result.ball);
}
});

CSharp Code : Action Method (returning a Json)

public ActionResult GetData(string value)
{
return Json(new {foo="bar", ball="dragon"});
}

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

2

Your function is a server code, but javascript is a client code, so it is not possible in that way. If you give us more information, we give you advice how to do what you need

1 Comment

I am building an html menu with my TreeViewAsUnorderedList function. That function receive and List<> as parameter from my GetPermissionsItems function. But my GetPermissionsItems function receive an int as parameter. That int value depends of the index of a DropDownListFor. But I dont know how to get the value of my DropDownListFor, so I put the value with javascript document.getElementByID('txtPerfil').value = document.getElementById('myddl').options[document.getElementById('myddl').selectedIndex].value; So, the thing here is that I dont know how to send that value to my function.

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.