Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4609122
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:56:31+00:00 2026-05-22T00:56:31+00:00

I would like to get help and guide on how can i manipulate text/string

  • 0

I would like to get help and guide on how can i manipulate text/string that being called from MS-SQL Database. So here is my SettingController.cs partial code for index viewing:

public ActionResult Index()
    {
        var datacontext = new SGM_SIDDataContext();
        var dataToView = from m in datacontext.SGMs
                         orderby m.Seq
                         select m;
        return View(dataToView.ToList());
    }

And This is my index.cshtml codes:

@model IEnumerable<MVC_Apps.Models.SGM>

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
            SID
        </th>
        <th>
            Abbrev
        </th>
        <th>
            Val
        </th>
        <th>
            Seq
        </th>
        <th></th>
    </tr>

@foreach (var item in Model)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.SID)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Abbrev)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Val)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Seq)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.GID })
        </td>
    </tr>
}

</table>

So roughly I got a View. Now here is what i would like to do:
1) The data ‘item.Val’ on Index.cshtml view will be like this:

A,L,C,H

and sort of like that. But the might be line where the data only contain:

H or C or none(Null value)

But if the data contain more than one char like say it does set for K and L, the data in item.Val will look like this:

A,L

Which the data being separate by comma. So now i want to split that item.Val data and do if statement on it. Where I would like to check every data in item.Val if it contain K or L or C or H or all of them or none of them(Sorry if my english is bad). And I would like to view it as , if all the data contain H so in table view, the will be column named Hotel while if the data also have L so another column of Lounge will be display with a check button being checked.

the possible char in item.Val is:

A = Admin
L = Lounge
H = Hotel
C = Customer

Any help and ideas much appreciated. Thank you in advanced.

Update information:

Thanks Im starting to get what is it. What i really want to do is, when the item.Val does contain H(which is for hotel) then the view will have table column with header name Hotel and at the record it will have tick checkbox.

This is sample picture of table view: http://imagebin.org/152941

But then the Hotel, Admin and User information either it is tick or not is in item.Val
For example for Smith, the item.Val data look like this : C,
For example for Anna , the item.Val data look like this : H,C,

P.S : – the var conf line is a test code. Ignore it as I already delete it from my source. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T00:56:32+00:00Added an answer on May 22, 2026 at 12:56 am

    Create a ViewModel similar to

    public class MyViewModel
    {
      // items from your model
      public int Id{get;get;}
      public String Vals{get;set;} // A,L,C,H
      ...
      ...
    
      public bool IsHotel
      {
        get
        {
           return Vals.Split(',').Contains("H");
        }
      }   
    
      public bool IsAdmin      
      {
        get
        {
           return Vals.Split(',').Contains("A");
        }
      } 
    
      public bool IsCust
      {
        get
        {
           return Vals.Split(',').Contains("C");
        }
      } 
    
    }
    

    In the controller action

    public ActionResult Index()
    {
       var datacontext = new SGM_SIDDataContext();
       var dataToView = from m in datacontext.SGMs
                        orderby m.Seq
                        select new MyViewModel()
                        {
                          // items from your datacontext
                          Id= m.SID, 
                          //etc...
    
                        };
       var conf = from m in datacontext.SGMs // what's the purpose of this query??
                         select m.Val;
    
       return View(dataToView.ToList());
    }
    

    The View will need to be updated, so include columns for Hotel, Cust, Admin and any others you need. I would suggest that you keep it simple and don’t try to create the HTML columns on the fly. If you want to do this, you probably will need to inspect all Vals in every object of your list first to determine what columns are needed. In the view

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.SID)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Abbrev)
            </td>
            <td>
              @(item.IsHotel? "Checked" : "")
            </td>
            <td>
              @(item.IsAdmin? "Checked" : "")
            </td>
            <td>
              @(item.IsCust? "Checked" : "")
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Seq)
            </td>
            <td>
                @Html.ActionLink("Edit", "Edit", new { id=item.GID })
            </td>
        </tr>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to get data from from different webpages such as addresses of
I would like to get some help on how to setup paypal payment with
I would like to get a sum from a column, with and without a
I would like to update my SQL lite database with the native update-method of
I would like to get a sample SOAP Request for a given action from
Would like to get a list of advantages and disadvantages of using Stored Procedures.
I would like to get up-to-date information on Google's index of a website, and
I would like to get the path to the execution directory of a Windows
I would like to get the absolute position of an element in relation to
I would like to get a list of the wireless networks available. Ideally this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.