如何在mvc视图中拆分字符串

时间:2017-06-14 05:44:21

标签: asp.net asp.net-mvc-4

@foreach (var item in User)


string title = item.FirstName;
string lat = item.Lat.Split('/').ToString();
string lng = lat;
string description = item.description;

但它显示的错误类似于System.ToString()

2 个答案:

答案 0 :(得分:0)

@foreach (var item in User)
{

string title = item.FirstName;
string lat = item.Lat.Split('/').ToString();
string lng = lat;
string description = item.description;

}

为什么你需要这个.ToString();

如果此工作正常string title = item.FirstName;

可能是它已经到来的字符串.. 将代码放入try catch {}并调试并查看确切的错误

答案 1 :(得分:0)

    @foreach (var item in User)
    {

    string title = item.FirstName;
    string lat = item.Lat;
    string latt=lat.Split('/');//text is hey/hi
    string latte  = latt[0];// if u want the 1st part like "hey"/hi this will give hey
    string latti  = latt[1];// if u want the 2nd part like hey/"hi" this will give hi
    string lng = lat;
    string description = item.description;

    }    

checkHere here here here 检查它们,看看你是否可以解决它