0

I read many posts about sending razor variables to javascript as funtion parameters, but nothing worked for me.

Here is my razor view:

string uniqueIdFirst = Model.Requests.FirstOrDefault().UniqueId;
@Html.DevExpress().Button( saveSett =>
{
    saveSett.Name = "btnCancelRequest";
    saveSett.Text = "Cancel";
    saveSett.Width = 63;
    saveSett.Height = 28;
    saveSett.ControlStyle.CssClass = "button";
    saveSett.Styles.EnableDefaultAppearance = false;
    saveSett.EnableClientSideAPI = true;
    saveSett.ClientSideEvents.Click = "function(s, e) { BtnCancelRequest('@uniqueIdFirst'); }";
} ).GetHtml();

When I debug javascript function BtnCancelRequest I see that I get just string "@uniqueIdFirst".

2 Answers 2

2

You have to use a js variable for that, try something like this:

<script type="text/javascript">
var uniqueIdFirst = '@Model.Requests.FirstOrDefault().UniqueId';
</script>

and in event :

saveSett.ClientSideEvents.Click = "function(s, e) { BtnCancelRequest(uniqueIdFirst); }";
Sign up to request clarification or add additional context in comments.

Comments

0

If you use external JS files, better way to create:

@{
    string uniqueIdFirst = Model.Requests.FirstOrDefault().UniqueId;
}

saveSett.ClientSideEvents.Click = "function(s, e) {BtnCancelRequest('" + uniqueIdFirst + "'); }";

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.