이것은 기본이어야하지만 컨트롤의 이름 특성에 값을 설정 한 FormCollection에 HTML 컨트롤을 추가하려고 생각했습니다. 그러나 이것은 아무런 영향을 미치지 않는 것 같습니다. 아래 코드에서 txtRating 및 FileUpload의 두 가지 컨트롤을 사용해보십시오 (둘 다 하단 근처). 내가 무엇을 잘못하고 있지? 메서드가 올바르게 호출되고 Html 도우미 컨트롤을 FormCollection에 넣지 만 추가하려고 한 컨트롤은 넣지 않습니다. 없어진 물건 있어요?
@using (Html.BeginForm("SaveReview", "Content", FormMethod.Post, new { enctype = "multipart/form- data", id = "photoform" }))
{
<fieldset>
@Html.Hidden("ReviewID", Model.ReviewID, new { @id = "hidReviewID" })
@Html.Hidden("RestaurantID", null, new { @id = "hidRestaurantID" })
@Html.Hidden("IsNewReview", Model.IsNewReview)
@Html.HiddenFor(m => m.UserID, new { @id = "hidUserID" })
@if (Model.IsInEditMode)
{
<div class="bodyc">
<div id="reviewsbody3" class="sectionbody1all">
<div class="reviewtxtrestaurant">
@Html.TextBoxFor(m => m.RestaurantNamePlusVicinity, htmlAttributes: new { id = "txtSearch", placeholder = "Search restaurant name", @style = "width:99%; margin:5px auto;display:block;" })
</div>
Visit Date: @Html.TextBoxFor(m => m.VisitDate, "{0:dd-MM-yyyy}", htmlAttributes: new { id = "txtVisitDate", @readonly = "readonly" })
Meal Type: @Html.DropDownListFor(m => m.MealTypeName, new SelectList(Model.MealTypes, "Value", "Text", "Dinner"))
</div>
</div>
}
else
{
<div class="bodyc">
<div id="reviewsbody3" class="sectionbody1all">
<div class="reviewtxtrestaurant">@Html.DisplayFor(m => m.RestaurantNamePlusVicinity, new { @style = "width:98%; margin:0px auto;display:block;" })</div>
Visit Date: @Html.DisplayFor(m => m.VisitDate, "{0:dd-MM-yyyy}")
Meal Type: @Html.DisplayFor(m => m.MealTypeName)
</div>
<div class="bottom"></div>
</div>
}
<div class="bodyc">
<div id="reviewsbody53" class="sectionbody1all">
@Html.TextAreaFor(m => m.Comment, new { id = "txtComment", maxlength = 120, @style = "width:99%;height:90%;margin:5px auto;display:block;" })
</div>
</div>
<div class="bodyc">
<div id="reviewsbody544" class="sectionbody1all">
<div class="slidergiant" style="float:left;width:50%;display:inline-block;position:relative;height:140px;">
<div style="margin:0px auto;">
<div id="sli" class="slider2" style="width:95%;margin:58px 10px 10px 10px;"></div>
<label id="txtRatingDescription" style="font-size:20px;margin:0px auto; width:100%;text-align:center;display:block;">average to good</label>
</div>
</div><div class="ratinggiant" style="float:right;width:50%;display:inline-block;position:relative;">
<div style="margin:0px auto;">
<img id="imgScore" src="~/Images/scorebackground180.png" style="width:130px;height:130px;position:absolute;top:4px;left:0px;z-index:0.9;" />
<label id="txtRating" name="txtRating" style="position:absolute;top:39px;left:32px;font-size:63px;color:white;z-index:1;">5.5</label>
</div>
<div class="valuechecks" style="width:100%;text-align:center;display: block;">
@Html.Label("Discounted:") @Html.CheckBoxFor(m => m.IsDiscountPrice) <br />
@Html.Label("Good Value:") @Html.CheckBoxFor(m => m.GoodValue)<br />
@Html.Label("Bad Value:") @Html.CheckBoxFor(m => m.BadValue) <br />
</div>
</div>
<div style="clear: both"></div>
</div>
</div>
<div class="bodyc">
<div id="reviewsbody4" class="sectionbody1all">
<input type="file" id="uploadFile" name="uploadFile" onchange="showimagepreview(this);" />
<div style="width:100px;height:100px;"><img id="imagepreview" alt="image preview" /></div>
</div>
</div>
</fieldset>
}
편집하다:
방법은 다음과 같습니다.
public ActionResult SaveReview(FormCollection f)
{
}
JQuery를 통해 설정된 클릭 이벤트와 함께 일반 버튼을 통해 게시됩니다.
$('#btnSave').click(function () {
$('#photoform').submit();
});
다음은 생성 된 HTML입니다.
<form action="/Content/SaveReview" enctype="multipart/form-data" id="photoform" method="post">
<fieldset>
<input data-val="true" data-val-required="The ReviewID field is required." id="hidReviewID" name="ReviewID" type="hidden" value="e0ee6f58-a8f0-4ff8-b6fc-3fd2ed591567" />
<input data-val="true" data-val-required="The RestaurantID field is required." id="hidRestaurantID" name="RestaurantID" type="hidden" value="00000000-0000-0000-0000-000000000000" />
<input data-val="true" data-val-required="The IsNewReview field is required." id="IsNewReview" name="IsNewReview" type="hidden" value="True" />
<input data-val="true" data-val-required="The UserID field is required." id="hidUserID" name="UserID" type="hidden" value="07a6e730-57ca-4d1e-b52b-988d85759501" />
<div class="bodyc">
<div id="reviewsbody3" class="sectionbody1all">
<div class="reviewtxtrestaurant">
<input id="txtSearch" name="RestaurantNamePlusVicinity" placeholder="Search restaurant name" style="width:99%; margin:5px auto;display:block;" type="text" value="" />
</div>
Visit Date: <input data-val="true" data-val-date="The field Visit Date must be a date." data-val-required="The Visit Date field is required." id="txtVisitDate" name="VisitDate" readonly="readonly" type="text" value="15-09-2014" />
Meal Type: <select id="MealTypeName" name="MealTypeName"><option value="Breakfast">Breakfast</option>
<option selected="selected" value="Dinner">Dinner</option>
<option value="Lunch">Lunch</option>
</select>
</div>
</div>
<div class="bodyc">
<div id="reviewsbody53" class="sectionbody1all">
<textarea cols="20" id="txtComment" maxlength="120" name="Comment" rows="2" style="width:99%;height:90%;margin:5px auto;display:block;">
</textarea>
</div>
</div>
<div class="bodyc">
<div id="reviewsbody544" class="sectionbody1all">
<div class="slidergiant" style="float:left;width:50%;display:inline-block;position:relative;height:140px;">
<div style="margin:0px auto;">
<div id="sli" class="slider2" style="width:95%;margin:58px 10px 10px 10px;"></div>
<label id="txtRatingDescription" style="font-size:20px;margin:0px auto; width:100%;text-align:center;display:block;">average to good</label>
</div>
</div><div class="ratinggiant" style="float:right;width:50%;display:inline-block;position:relative;">
<div style="margin:0px auto;">
<img id="imgScore" src="/Images/scorebackground180.png" style="width:130px;height:130px;position:absolute;top:4px;left:0px;z-index:0.9;" />
<label id="txtRating" name="txtRating" style="position:absolute;top:39px;left:32px;font-size:63px;color:white;z-index:1;">5.5</label>
</div>
<div class="valuechecks" style="width:100%;text-align:center;display: block;">
<label for="Discounted:">Discounted:</label> <input data-val="true" data-val-required="The IsDiscountPrice field is required." id="IsDiscountPrice" name="IsDiscountPrice" type="checkbox" value="true" /><input name="IsDiscountPrice" type="hidden" value="false" /> <br />
<label for="Good_Value:">Good Value:</label> <input data-val="true" data-val-required="The GoodValue field is required." id="GoodValue" name="GoodValue" type="checkbox" value="true" /><input name="GoodValue" type="hidden" value="false" /><br />
<label for="Bad_Value:">Bad Value:</label> <input data-val="true" data-val-required="The BadValue field is required." id="BadValue" name="BadValue" type="checkbox" value="true" /><input name="BadValue" type="hidden" value="false" /> <br />
</div>
</div>
<div style="clear: both"></div>
</div>
</div>
<div class="bodyc">
<div id="reviewsbody4" class="sectionbody1all">
<input type="file" id="uploadFile" name="uploadFile" onchange="showimagepreview(this);" />
<div style="width:100px;height:100px;"><img id="imagepreview" alt="image preview" /></div>
</div>
</div>
</fieldset>
</form>
FormCollection의 값은 현재 다음과 같습니다.
고마워, 롭
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다