public static MvcForm BeginFormAnchor(this HtmlHelper htmlHelper, string actionName, string controllerName, object routeValues, FormMethod method, object htmlAttributes, string hashTag)
{
var formAction = UrlHelper.GenerateUrl(null, actionName, controllerName, htmlHelper.ViewContext.HttpContext.Request.Url.Scheme, null, hashTag, ConvertToRouteValueDictionary(routeValues), htmlHelper.RouteCollection, htmlHelper.ViewContext.RequestContext, true);
var builder = new TagBuilder("form");
builder.MergeAttribute("action", formAction);
builder.MergeAttribute("method", method.ToString(), true);
foreach (KeyValuePair<string, string> attribute in ConvertToDictionaryStringString(htmlAttributes))
{
builder.MergeAttribute(attribute.Key, attribute.Value);
}
htmlHelper.ViewContext.Writer.Write(builder.ToString(TagRenderMode.StartTag));
return new MvcForm(htmlHelper.ViewContext);
}
private static Dictionary<string, string> ConvertToDictionaryStringString(object obj)
{
return obj.GetType().GetProperties().ToDictionary(o => o.Name, o => o.GetValue(obj, null).ToString());
}
private static RouteValueDictionary ConvertToRouteValueDictionary(object obj)
{
RouteValueDictionary rvd = new RouteValueDictionary();
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(obj);
foreach (PropertyDescriptor prop in props)
{
rvd.Add(prop.Name, prop.GetValue(obj));
}
return rvd;
}
다음과 같은 형식으로 지정합니다.
@using (Html.BeginFormAnchor("Action", "Controller", new { id = Model.ID }, FormMethod.Post, new { @id = "formID" }, "anchorName"))
클라이언트 측 유효성 검사에 반대하십니까? 그러면 오류 메시지가 나타납니다. 게시하지 않고 제출을 클릭하면 ... –
jQuery 솔루션 - http://stackoverflow.com/questions/9363508/scroll-to-validation-summary-asp-net-mvc/ 9382969 # 9382969 –
음, 두 가지 문제가 있습니다. 하나는 MicrosoftAjax.js, MicrosoftMvcAjax.js 및 MicrosoftMvcValidation.js입니다. 또한이 : 이 <키 = "UnobtrusiveJavaScriptEnabled"값 = "true"를 추가 /> appSettings는> 하지만, 내가 실행할 때 <= "true"로/키 = "ClientValidationEnabled"값을 추가>가 디버그 모드에서 여전히 내 컨트롤러를 때리고있다. 또한 JS가 꺼져있는 경우이 솔루션을 사용하고 싶습니다. –
ScubaSteve