Usually I hate people who don't answer a question directly, but offer a "why don't you ... instead" solution. Yet here I go... ;-)
Maybe you still like the solution.
Because of refactoring, I recently managed to break javascript code (mostly jquery selectors) very similar to yours.
Through adding the following extensions to the HtmlHelper (I didn't come up with them, found them on the web)
public static string GetFullHtmlFieldName<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression) {
return helper.ViewData.TemplateInfo.GetFullHtmlFieldName(expression);
}
public static string GetFullHtmlFieldId<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression) {
return helper.ViewData.TemplateInfo.GetFullHtmlFieldId(expression);
}
public static string GetFullHtmlFieldName<TModel, TProperty>(this TemplateInfo templateInfo, Expression<Func<TModel, TProperty>> expression) {
return templateInfo.GetFullHtmlFieldName(ExpressionHelper.GetExpressionText(expression));
}
public static string GetFullHtmlFieldId<TModel, TProperty>(this TemplateInfo templateInfo, Expression<Func<TModel, TProperty>> expression) {
return templateInfo.GetFullHtmlFieldId(ExpressionHelper.GetExpressionText(expression));
}
I was able to make my selectors "model-type-safe":
var id = $('#@Html.GetFullHtmlFieldId(model => model.Id)').val();
While this isn't a direct solution for your problem, it will satisfy ReSharper, and you get the extra benefit of "model-type-safety"
The only downside is that it makes your JavaScript code a bit uglier - personally I prefer that over things breaking silently.