문제

이] [1] 문제를 해결하기 위해 주위를 돌면 문제의 핵심이 다음과 같습니다.

html.radiobutton () HTML 헬퍼를 값 필드로 사용하는 경우 옵션을 한 번만 선택할 수 있습니다. 페이지를 다시 게시 한 후, 헬퍼는 통화의 값을 무시하고 모든 라디오 버튼을 동일한 값으로 설정하여 이전 게시물을 선택한 값입니다. 내가 뭔가 잘못하고 있습니까?

예제 (보기 버튼)

<fieldset>
    <legend>Test</legend>                            
    <div>
        <label for="SearchBag.EffectIndicatorAny" id="EffectIndicatorAnyLabel">
            Any
        </label>                
        <%=Html.RadioButton("SearchBag.EffectIndicator", "Any" , ViewData.Model.SearchBag.EffectIndicatorIsAny, new { @id = "SearchBag.EffectIndicatorAny" })%>
    </div>
    <div>
        <label for="SearchBag.EffectIndicatorSolid" id="EffectIndicatorSolidLabel">
            Solid
        </label>                
        <%=Html.RadioButton("SearchBag.EffectIndicator", "Solid", ViewData.Model.SearchBag.EffectIndicatorIsSolid, new { @id = "SearchBag.EffectIndicatorSolid" })%>
    </div>
    <div>
        <label for="SearchBag.EffectIndicatorEffect" id="EffectIndicatorEffectLabel">
            Effect
        </label>                
        <%=Html.RadioButton("SearchBag.EffectIndicator", "Effect", ViewData.Model.SearchBag.EffectIndicatorIsEffect, new { @id = "SearchBag.EffectIndicatorEffect" })%>
    </div>
</fieldset>

생성됩니다

<fieldset>
    <legend>Effect</legend>                            
    <div class="horizontalRadio">
        <label for="SearchBag.EffectIndicatorAny" id="EffectIndicatorAnyLabel">
            Any                                      
        </label>                
        <input checked="checked" id="SearchBag.EffectIndicatorAny" name="SearchBag.EffectIndicator" type="radio" value="Any" />
    </div>
    <div class="horizontalRadio">
        <label for="SearchBag.EffectIndicatorSolid" id="EffectIndicatorSolidLabel">
            Solid
        </label>                
        <input id="SearchBag.EffectIndicatorSolid" name="SearchBag.EffectIndicator" type="radio" value="Solid" />
    </div>
    <div class="horizontalRadio">
        <label for="SearchBag.EffectIndicatorEffect" id="EffectIndicatorEffectLabel">
            Effect
        </label>                
        <input id="SearchBag.EffectIndicatorEffect" name="SearchBag.EffectIndicator" type="radio" value="Effect" />
    </div>
</fieldset>

두 번째로 생성됩니다.

<fieldset>
    <legend>Effect</legend>                            
    <div class="horizontalRadio">
        <label for="SearchBag.EffectIndicatorAny" id="EffectIndicatorAnyLabel">
            Any                                      
        </label>                
        <input id="SearchBag.EffectIndicatorAny" name="SearchBag.EffectIndicator" type="radio" value="Solid" />
    </div>
    <div class="horizontalRadio">
        <label for="SearchBag.EffectIndicatorSolid" id="EffectIndicatorSolidLabel">
            Solid
        </label>                
        <input checked="checked" id="SearchBag.EffectIndicatorSolid" name="SearchBag.EffectIndicator" type="radio" value="Solid" />
    </div>
    <div class="horizontalRadio">
        <label for="SearchBag.EffectIndicatorEffect" id="EffectIndicatorEffectLabel">
            Effect
        </label>                
        <input id="SearchBag.EffectIndicatorEffect" name="SearchBag.EffectIndicator" type="radio" value="Solid" />
    </div>
</fieldset>
도움이 되었습니까?

해결책

이는 ASP.NET MVC 베타 코드의 버그 때문입니다. ASP.NET MVC 포럼 에서이 문제에 대한 전체 설명을 썼습니다. 이것을 참조하십시오 링크

다른 팁

누구든지 여기에 관심이있는 경우 프레임 워크의 다음 업데이트를 기대하는 데있어 정말 빠르고 더러운 작업이 있습니다. 그것은 당신의 값으로 값을 다시 표시합니다. 그것은 단위 테스트가 아니며 어떤 것도 보장하지 않습니다.

htmlhelper 클래스 라이브러리 또는 Htmlhelper extentions를 어디에나 넣으십시오. 다음 결과 추가 :

  • System.text.regularexpressions;
  • System.Web.mvc.html;

    /*ToDo: remove when patched in framework*/
    public static string MonkeyPatchedRadio(this HtmlHelper htmlHelper, string name, object value, bool isChecked, object htmlAttributes){
        string monkeyString = htmlHelper.RadioButton(name, value, isChecked, htmlAttributes);
        monkeyString = Regex.Replace(monkeyString, "(?<=value=\").*(?=\".*)", value.ToString());            
        return monkeyString;
    }
    

나는 그것이 더 잘할 수 있고 무엇을 할 수 있다는 것을 알고 있지만, 어쨌든 곧 그것이 수정되기를 바랍니다. 더 나아지고 싶다고 느끼면 커뮤니티 위키입니다.

확인해야 할 한 가지. 업데이트 된 모델을 사용하여보기를 렌더링하고 있습니까? IE는 두 번째로 표시된 뷰로 전달 된 게시물에서 업데이트 된 동일한 모델 데이터입니까?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top