I am reading through a table in jquery and I am trying to pass the value to a method from a class. I am trying to write the following but can`t figure what is wrong.
The error message is on the line if...:
MvcUI\Views\Shared\employee.cshtml(170,81): error CS1646: Keyword, identifier, or string expected after verbatim specifier: @ MvcUI\Views\Shared\employee.cshtml(170,83): error CS1056: Unexpected character '$' MvcUI\Views\Shared\employee.cshtml(170,90): error CS1056: Unexpected character '$' MvcUI\Views\Shared\employee.cshtml(170,103): error CS1012: Too many characters in character literal
Help please.
if($.trim($(this).find('td:first').text())!='')
{
@{
if (MvcUI.Employee.ContainsName(@:$.trim($(this).find('td:first').text())))
{
@:$($(this).find('td:first').html($(this).find('td:first').text() + "<br />N开发者_如何转开发ame");
}
}
}
There 2 way to do what you want:
- Preload employer names into some js array
- Use ajax to check if name is registred
I will describe the second way.
The JS code:
var tdText = jQuery.trim($(this).find('td:first').text());
if(tdText != '') {
jQuery.post
(
'/some_route/employers/checkname',
{
name = tdText
},
function(rsp) {
if(rsp == 'true') {
alert("name is registered"); //replace by your code
}
else
{
alert("name isn't registered"); //replace by your code
}
}
);
}
The C# controller code:
[HttpPost]
public ActionResult CheckName(string name)
{
return Json(MvcUI.Employee.ContainsName(name));
}
精彩评论