Matt Stewart
Matt Stewart

Reputation: 322

Razor syntax incorrect?? jquery function onchange of Html.DropDownList

I need to call a jquery function through the onchange event of this DropDownList. I've googled and googled and can't find out why my razor syntax is wrong. Help please?

@Html.DropDownListFor(model => model.Type, (List<SelectListItem>)Type, new { @onchange = "reloadDial(" + @Model.AppID, @Model.LoginID, @Model, @ViewBag.Edit + ")"})    

The error is in the last part. @ViewBag.Edit + ")"}) Error is "Invalid anonymous type declarator. Anonymous type members must be declared with a member assignment, simple name or member access."

Upvotes: 2

Views: 1426

Answers (1)

Gabe
Gabe

Reputation: 50493

Looks like the problem is you're trying to concatenate some arguments for the javascript function. Your arguments are not in a string, so the compiler thinks you're trying to add more properties to the anonymous object.

So...

"reloadDial(" + @Model.AppID, @Model.LoginID, @Model, @ViewBag.Edit + ")"

should be:

"reloadDial('" + @Model.AppID + "','" + @Model.LoginID + "','" +  @Model + '",'" + @ViewBag.Edit + ")"

Upvotes: 6

Related Questions