开发者

TemplateInfo into Controller

how can i get a form field id after submitting the form. im trying like this:

ViewData.TemplateInfo.GetFullHtmlFieldId(logOnParts.Part.UserNameOrEmail)

but n开发者_开发问答o work on controller side. i need to get "Part_UserNameOrEmail" something..

if (String.IsNullOrEmpty(logOnParts.Part.UserNameOrEmail))
{
    ModelState.AddModelError("Part_UserNameOrEmail", "error");
    TempData["logon-focus-field"] = "Part_UserNameOrEmail";
}

so i will focus the field on view side like this:

$(document).ready(function () {
    $('#TempData["logon-focus-field"]').focus();
});


A controller should absolutely not need such information. The generated id is a view specific information. If you need this in a controller this simply means that you have some serious design problem with your application. Unfortunately as you haven't explained your scenario in the question it is difficult to help you solving this problem. So in your controller you could do this:

Expression<Func<MyViewModel, string>> expression = x => x.Part.UserNameOrEmail;
string name = ExpressionHelper.GetExpressionText(expression);
string id = new TemplateInfo().GetFullHtmlFieldId(name);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜