나는 .cshtml
파일의 코드 조각 아래에 있습니다.수없는 동적
<div class="row">
<input type="text" placeholder="Enter POR ID" id="porID" class="col-md-2 input-sm" name="porTextBox">
<button class="btn btn-primary col-md-2 btn-sm" style="margin-left:15px;width:150px;" type="submit" id="btnCreateTFSItems"><strong>Create TFS Items</strong></button>
@if (TempData["formState"] != null)
{
//@Html.Label("lblsuccess", "Successfully created TFS Work Items!")
<label id="lblsuccess" style="color:green; visibility:visible"> Successfully created TFS Work Items!</label>
}
</div>
하고 버튼 스크립트 태그에 아래의 함수를 호출한다 :
<script type="text/javascript">
$(document).ready(function (e) {
$('#btnCreateTFSItems').click(function() {
var txt = $('#porID');
var errorLabel = $('#lblError');
if (txt.val() != null && txt.val() != '') {
//alert('clicked');
$.ajax({
url: '@Url.Action("CreateWorkItems", "Tables")',
type: 'POST',
data: { 'porTextBox': $('#porID').val() }
});
// alert('Successfully added');
}
else {
errorLabel.text("Please enter valid PORID");
return false;
}
});
$("#porID").keypress(function (e) {
var errorLabel = $('#lblError');
errorLabel.text("");
//if the letter is not digit then display error and don't type anything
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
return false;
}
});
});
문제는 .cshtml
파일에, 그것은 상태를 확인하고 있습니다 만의 레이블을 추가 할 수 없습니다. 이유는 페이지를 새로 고쳐서 레이블을 렌더링 할 수 없기 때문일 수 있습니다. 나는 UI 개발에 익숙하지 않았으므로 인터넷에서 찾은 특정 옵션을 시도했지만 제대로 작동하지는 못했습니다. 내가 이걸 얻을 수있는 방법이 있니? 페이지가 레이블을 렌더링하는 데 상쾌하지 않기 때문에
? 당신이 방법은 내가 버튼 태그 아래에 별도의 사업부에 레이블을 추가하는 시도했지만 여전히 내가 할 수없는 오전 –
을 (사용자의 입력이 비어있는 경우에만 그것을 값을 제공)') (은'키 누름에 빈 문자열로 설정 값을 지정하십시오. –
페이지가 처음 렌더링 될 때'TempData [ "formState"]'의 값은 무엇입니까? - 만약'null'이라면 레이블은 존재하지 않습니다. 여기에 당신이 무엇을하려고하는지 명확히하지 마십시오 –