Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
F

Farhad Eft

@Farhad Eft
About
Posts
92
Topics
51
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Implementation advice for quiz with 4 choice questions
    F Farhad Eft

    I found this awesome post about solving my issue: asp.net mvc 3 - Getting a list of radio button values in ASP MVC 3 - Stack Overflow[^]

    ASP.NET asp-net question csharp html architecture

  • Implementation advice for quiz with 4 choice questions
    F Farhad Eft

    Hey, I', looking for some implementation advice. I am creating this ASP.NET MVC page for quizzes that each course may have a different number of questions with 4 choices. I would like to send the questions to my view as my Model, and by submitting the form, my controller endpoint receives the Id of the questions and selected answers. Can you please give me some tips that how to send such information to my controller using the sample code I wrote in the following? Thank you in advance. My Model

    public class QuizQuestion
    {
    [Key]
    public int QuestionId { get; set; }
    public int CourseId { get; set; }
    public int Order { get; set; }
    public string Question { get; set; }
    public string Choice1 { get; set; }
    public string Choice2 { get; set; }
    public string Choice3 { get; set; }
    public string Choice4 { get; set; }
    public int RightAnswer { get; set; }
    }

    My View

    using (Html.BeginForm("Submit", "Quiz", FormMethod.Post, new { }))
    {
    @Html.AntiForgeryToken()
    foreach (var item in Model.QuizJustQuestionsDto)
    {

                            @(item.Order + ". " + item.Question)  
                            @Html.RadioButton(item.QuestionId.ToString(), 1) @Html.Label(item.Choice1)  
                            @Html.RadioButton(item.QuestionId.ToString(), 2) @Html.Label(item.Choice2)  
                            @Html.RadioButton(item.QuestionId.ToString(), 3) @Html.Label(item.Choice3)  
                            @Html.RadioButton(item.QuestionId.ToString(), 4) @Html.Label(item.Choice4)
                        
    
                        }
    
    ASP.NET asp-net question csharp html architecture

  • Getting Route Values in Controller
    F Farhad Eft

    Nice! Thank you! :)

    ASP.NET database question

  • Getting Route Values in Controller
    F Farhad Eft

    Hi, I have the following Route Contex:

    context.MapRoute(
    "Space_default",
    "Space/{Value}/{controller}/{action}/{id}",
    new { action = "Index", id = UrlParameter.Optional }
    );

    And I would like to get {Value} in my controller in the following code:

    public class OverviewController : Controller
    {
        string myValue = (int)RouteData.Values\["Value"\];
    
        \[CourseAccess(CourseId = myValue)\]
        public ActionResult Index(int CourseId)
        {...
    

    I was wondering how can I do that and use that value before my actions. Thank you.

    ASP.NET database question

  • MVC Application RoleManager issue after being deployed in Azure
    F Farhad Eft

    I have an issue with my ASP.NET MVC4 application when I publish it to Azure. The roleManager part is not working and the application returns an error when it reaches to this code in my view:

    bool isAdmin = User.IsInRole("admin");

    And the error is the following:

    A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    SQLExpress database file auto-creation error: 
    
    The connection string specifies a local Sql Server Express instance using a database location within the application's App\_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:
    
    If the application is running on either Windows 7 or Windows Server 2008R2, special configuration steps are necessary to enable automatic creation of the provider database. Additional information is available at: http://go.microsoft.com/fwlink/?LinkId=160102. If the application's App\_Data directory does not already exist, the web server account must have read and write access to the application's directory. This is necessary because the web server account will automatically create the App\_Data directory if it does not already exist.
    If the application's App\_Data directory already exists, the web server account only requires read and write access to the application's App\_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the application's App\_Data directory. Revoking read access on the App\_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write
    
    ASP.NET asp-net database sysadmin help csharp

  • Regex uppercase
    F Farhad Eft

    Oh my! You guys are right!

    Regex regexEEST = new Regex(".*?EEST.*?",
    RegexOptions.IgnoreCase |
    RegexOptions.CultureInvariant |
    RegexOptions.IgnorePatternWhitespace |
    RegexOptions.Compiled);

    I didn't notice

    RegexOptions.IgnoreCase

    Thank you, your comments were very helpful.

    C# question regex

  • Regex uppercase
    F Farhad Eft

    Hi, I created my regex like the following:

    Regex regexEET = new Regex(".*?EET.*?");

    But this one also detects "eet". I was wondering how can I modify it to only search for uppercase "EET". Thank you.

    C# question regex

  • Removing an element from the content of a string value which is HTML code
    F Farhad Eft

    You are amazing! Thanks! :)

    C# html

  • Removing an element from the content of a string value which is HTML code
    F Farhad Eft

    Hi, I have a string variable which the value is html code. I like to check to see if certain word (in this case EEST) exist in the first

    element as you can see in the sample. Then I like to remove that element and its content from the string.

    Some text here, 26 APRIL 2017 AT 9:00 AM EEST. some other content here as well>

    much other elements here as well

    then the output becomes:

    much other elements here as well

    I was wondering, how I can do such task. Thank you.

    C# html

  • Using Base Model in Shared View
    F Farhad Eft

    Thank you for your help :)

    ASP.NET csharp asp-net linq com architecture

  • Using Base Model in Shared View
    F Farhad Eft

    Hi, I would like to have a Base Model and use it in my _Shared view. I followed some examples online and did the following but I was unable to make it work: _Layout view:

    @model Portal.Models.BaseViewModel

    Hi, @Model.FirstName

    Base Model:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    namespace Portal.Models
    {
    public class BaseViewModel
    {
    public String FirstName { get; set; }
    }
    }

    Base Controller:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Portal.Models;

    namespace Portal.Controllers
    {
    public class BaseController : Controller
    {
    public BaseController()
    {
    BaseViewModel baseModel = new BaseViewModel()
    {
    FirstName = "John"
    };
    }
    }
    }

    Dashboard Controller:

    public class DashboardController : BaseController

    When I run the application, I get the following error for @Model.FirstName:

    System.NullReferenceException: 'Object reference not set to an instance of an object.'

    Am I missing something? Thank you for your time and consideration.

    ASP.NET csharp asp-net linq com architecture

  • Merging 2 different JSON objects
    F Farhad Eft

    Thanks, it worked as you guided. I thought maybe there is already some sort of online tools to import and export such task.

    C# json tutorial question

  • Merging 2 different JSON objects
    F Farhad Eft

    Hi, I have two JSON objects: JSON Object 1

    [{
    "date":
    [
    "date-value1",
    "date-value2,
    ........ ,
    "date-value729"
    ]
    }]

    JSON Object 2

    {
    "data": [
    {
    "body": [ "body1" ],
    "link": "link1",
    "title": [ "title1" ]
    },
    ...........
    {
    "body": [ "body729" ],
    "link": "link729",
    "title": [ "title729" ]
    }
    ]
    }

    How can I merge the properties of these 2 JSON objects and have the following example as an output for all 729 records of data:

    {
    "data": [
    {
    "body": [ "body1" ],
    "link": "link1",
    "title": [ "title1" ].
    "date": "date1"
    },
    ...........
    {
    "body": [ "body729" ],
    "link": "link729",
    "title": [ "title729" ]
    "date": "date729"
    }
    ]
    }

    Examples that I found online are mainly about merging two identical JSON objects. Thank you in advance for your time and consideration.

    JavaScript json tutorial question

  • Merging 2 different JSON objects
    F Farhad Eft

    Hi, I have two JSON objects: JSON Object 1

    [{
    "date":
    [
    "date-value1",
    "date-value2,
    ........ ,
    "date-value729"
    ]
    }]

    JSON Object 2

    {
    "data": [
    {
    "body": [ "body1" ],
    "link": "link1",
    "title": [ "title1" ]
    },
    ...........
    {
    "body": [ "body729" ],
    "link": "link729",
    "title": [ "title729" ]
    }
    ]
    }

    How can I merge the properties of these 2 JSON objects and have the following example as an output for all 729 records of data:

    {
    "data": [
    {
    "body": [ "body1" ],
    "link": "link1",
    "title": [ "title1" ].
    "date": "date1"
    },
    ...........
    {
    "body": [ "body729" ],
    "link": "link729",
    "title": [ "title729" ]
    "date": "date729"
    }
    ]
    }

    Examples that I found online are mainly about merging two identical JSON objects. Thank you in advance for your time and consideration.

    C# json tutorial question

  • getting img tag src attribute values from a text file using C#
    F Farhad Eft

    Actually in the end, I found it much easier for the task to be done in Python using the following code:

    import urllib
    f = urllib.urlopen("URL")
    s = f.read()
    f.close()

    from bs4 import BeautifulSoup
    soup = BeautifulSoup(s)

    inputTags = soup.find_all("img", attrs={"src":True})

    output = [ x["src"] for x in inputTags ]

    print output

    And yep I know this is C# forum! :D

    C# csharp html

  • getting img tag src attribute values from a text file using C#
    F Farhad Eft

    Oh ok, thanks guys, I will give it a try then :thumbsup:

    C# csharp html

  • getting img tag src attribute values from a text file using C#
    F Farhad Eft

    That was a nice project but the problem is my content is coming from a json file, not a single html page.

    C# csharp html

  • getting img tag src attribute values from a text file using C#
    F Farhad Eft

    Hi, I have a text file that contains html tags. I like to use C# to read this file and list all the src attributes of tags. I was wondering how I can read through my file and list all of them. Thank you in advance for your time and consideration.

    C# csharp html

  • Problem in deserializing a JSON object in C#
    F Farhad Eft

    You guys are simply amazing!! Thank you! :)

    C# csharp help json linq com

  • Problem in deserializing a JSON object in C#
    F Farhad Eft

    Hi, When I try the following code, I receive an error which says:

    Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[Test.Program+NewsItem]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.

    To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.

    Path 'data', line 2, position 8.'

    On this line:

    List items = JsonConvert.DeserializeObject>(json);

    Here is my Code:

    using Newtonsoft.Json;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text.RegularExpressions;
    using System.Web.Script.Serialization;

    namespace Test
    {
    public class Program
    {
    public class News
    {

            public IList data { get; set; }
        }
    
        public class NewsItem
        {
    
            public IList title { get; set; }
            public IList body { get; set; }
        }
    
        public static void Main(string\[\] args)
        {
            string json = "";
            using (StreamReader r = new StreamReader("data3.json"))
            {
                json = r.ReadToEnd();
                List items = JsonConvert.DeserializeObject\>(json);
            }
    
            List  allNews = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize\>(json);
    
            foreach (var item in allNews)
            {
    
                foreach (var record in item.data)
                {
                    Console.WriteLine(record.title);
                    Console.WriteLine(record.body);
                }
                Console.ReadLine();
            }
        }
    }
    

    }

    And here is my JSON sample object:

    {
    "data": [{
    "body": ["

    part 1-1

    ", "

    part 1-2

    "],
    "link": "http://www.test.com",
    "title": ["sample title 1"]
    },
    {
    "body": ["

    part 2-1

    ", "

    part 2-2

    "],
    "link": "http://www.test.com",
    "title": ["sample title 2"]
    }
    ]
    }

    Thank you in advance for your time and considera

    C# csharp help json linq com
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups