我在C#中使用xx.Contains时出现错误信息

Ala*_*an2 0 c# asp.net-mvc razor asp.net-mvc-3

我在ASP MVC Razor文件中尝试以下代码:

       var topic = ViewData["TopicID"];
        var mustBeReplaced = string.Empty;
        var topicValue = Model.Topic;
        var replaceResult = string.Empty;
        if (topic.Contains(topicValue)) {
            mustBeReplaced = "value=\"" + topicValue + "\"";
            replaceResult = mustBeReplaced + " selected=\"selected\"";
            topic = topic.Replace(mustBeReplaced, replaceResult);             
        }
Run Code Online (Sandbox Code Playgroud)

但是我收到一条错误消息:

object'不包含'Contains'的定义和最佳扩展方法重载

ozc*_*cho 7

var topic = ViewData["TopicID"];
Run Code Online (Sandbox Code Playgroud)

返回对象.你需要强制转换为字符串.