-1
我在.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开发,所以我尝试了一些我在网上找到的选项,但无法使其工作。有什么办法可以做到这一点?
你是什么意思_不添加label_?您在'keypress()'方法中将其设置为空字符串(并且只在输入为空的情况下给它一个值) –
我已经尝试在按钮标记下方的单独div中添加标签,但仍然无法赋值给它。 –
当页面第一次渲染时,TempData [“formState”]的值是什么 - 如果它的'null',那么标签将不存在。不清楚你试图在这里做什么 –