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
X

xnaLearner

@xnaLearner
About
Posts
45
Topics
29
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • read an excel file
    X xnaLearner

    In my asp.net dynamic data project I want to read an excel file using suitable Microsoft technology (Not Excel). Someone said their was a server side tool for this? I want to read the first few columns of data from a table?

    Any suggestions or directions on where to go?

    .NET (Core and Framework) csharp asp-net sysadmin question

  • xna4life Member 13 Points 71 Posts hard code drop down instead of using toolbar and r/s
    X xnaLearner

    So im trying to creae a dynamic data project using asp.net.

    my project has 2 tables, FruitTable and SellerTable.

    I had it set so the primary key in 'fruit table': name. was the foreign key in 'seller table'

    I added a new class which contains the code to link to the new fieldTemplate I added(DropDown)

    [MetadataType(typeof(UsingDropDownMetadata))]
    public partial class UsingDropDown
    {
    }

    public class UsingDropDownMetadata
    {
        //DropDown is name of field templates
        \[UIHint("DropDown")\]
        //use in field date in tracing table
        public object DropDownFromTextBox { get; set; }
    }
    

    then in the dropDown_Edit.ascx I used the toolbox to get a drop down list and link it to the fruit table.

    Now when a user creates a new item, they can select the names of fruit to add.

    However I would like to hard code this so I have removed the r/s btn fruit and seller table

    In dropdownEdit.ascx iv added it manuall

    <asp:DropDownList id="DropDownList1" runat="server"
    DataSource="<% databindingexpression %>"
    DataTextField="DataSourceField"
    DataValueField="DataSourceField"
    AutoPostBack="True|False"
    OnSelectedIndexChanged="OnSelectedIndexChangedMethod">

    <asp:ListItem value="value" selected="True|False">
    Text
    </asp:ListItem>

    </asp:DropDownList>
    then in the dropdownedit.ascx.cs

    I want to hard code to pull across the values but am not sure if I am doing this right. please advise

    protected void OnSelectedIndexChangedMethod(object sender, EventArgs e)
    {

    //text here

    }

    JavaScript csharp asp-net wpf sysadmin

  • Only 1 use for admin?
    X xnaLearner

    The system currently has a few users, created from the login feature used with mvc3 razor. how Can I assign one of these users to the administrator? thanks

    ASP.NET question asp-net

  • Have userID in view, need userName posted
    X xnaLearner

    in my Get/Index view I am posting to my Post/Index method in the holidayController. So i am posting over the UserID, how can I use this to access the userName? Iv tried

    public ViewResult Index(int userID, string userName)
    {
    Person person = new Person();
    //this assigns person.Id to the user Id
    person.Id = userID;
    //i want to assign name of person to the string userName
    userName = person.name;
    }

    This is flashing up cant be null for person.name?

    ASP.NET question database

  • sequence contains no elements
    X xnaLearner

    hey matt...thanks for teh reply man that sorted it

    ASP.NET database help question learning

  • How to access 'name' given when user registers
    X xnaLearner

    forgot to mention Its just the automatic login that comes with mvc3 razor

    ASP.NET database tutorial question learning

  • How to access 'name' given when user registers
    X xnaLearner

    So I only want the logged in user to be allowed to book holidays for them selves. I think the easiest way to do this is to compare 'name' of logged in user againast 'name' in person table. So....

    public ActionResult Create()
    {
    string xx = (string)Session["usernameID"];
    int? currentPersonID = Convert.ToInt32(xx);

            string userNameComparedAgainstLoginName = // here is where i want to say 'name' of logged in user
    
            CreateModel model = new CreateModel();
            model.currentPersonID = currentPersonID.Value;
            model.PList4DD = db.People.ToList();   
           
    
            if (userNameComparedAgainstLoginName == model.userName)
            {
                ViewBag.Id = new SelectList(db.People, "Id", "Name");
                return View(model);
            }
            else
            {
                TempData\["canOnlyBookHolidaysForYourself"\] = "I'm afraid you can only book holidays for yourself";
                return RedirectToAction("Index");
            }
        } 
    

    --------------------------------------- the name given when the user registers will be the same names used in the db. So could someone tell me how I can access the logged in 'name'? Thanks

    ASP.NET database tutorial question learning

  • sequence contains no elements
    X xnaLearner

    So a drop down is used to select the users name, then click 'view' and it will display all the holidays this user has previously booked. From here the user can click 'create new' which will bring them to a create new page. Instead of having to re-select their name from another drop down i carried across the currentuserID and replaced the second drop down with the users ID. Everything was working fine with 2 separate drop downs, the user could book holidays etc... However now (after I changed the second drop down to hold the ID value) I am getting an error from my listHoliday Method in my controller: Error: InvalidOperationException was unhandled by the user code Sequence contains no elements var dbPerson1 = (from p in db.People where p.Id == PersonId select p).Single(); Could anyone advise what to do? Im lost thanks for any replies.

    ASP.NET database help question learning

  • error accessing model from view
    X xnaLearner

    So bit too late in the project to be at this but i'm tidying up my project to try and refine a error I am receiving. Where I was using some of my model classes for many methods in my HolidayCotroller, So im trying to just run one method from one model. renamed all the files and everything seems to be ok except for my index method In my View for Index im using @model HolidayBookingApp.Models.IndexModel but when i click on the below link in the UI: @Html.ActionLink("Holidays Remaining", "HolidaysRemaining") the error states: The model item passed into the dictionary is of type 'HolidayBookingApp.Models.IndexModel', but this dictionary requires a model item of type 'HolidayBookingApp.Models.HolidaysRemainingModel' So I change the model to: @model HolidayBookingApp.Models.HolidaysRemainingModel but it is still giving me the same error msg. So in my IndexModel.cs i created a new instance of the previous HolidayremainingModel.cs` HolidaysRemainingModel model = new HolidaysRemainingModel(); what now?

    ASP.NET html database design help question

  • [session] returns null
    X xnaLearner

    I want to store the users ID from the previous drop down so it will update automatically if they try to create another holiday (to replace the second drop down) Im using a session variable to do this, My View: //this coverts the user ID to a string and stores it in

    session["usernameID"]
    string userID = currentPersonID.ToString();
    Session["usernameID"] = userID;

    ------------------------------------------------- //My Create: //catches the session["UsernameID"], stores it in string 'xx' //converts it to an int and stores it in currentPersonID //then store the value of currentpersonID in the model

    public ActionResult Create()
    {
    string xx = (string)Session["usernameID"];

        int? currentPersonID = Convert.ToInt32(xx);
    
        HolidayList model = new HolidayList();
        model.currentPersonID = currentPersonID.Value;
    

    ------------------------------------------------- This all works fine, howeve how do I display the value properly in the view? Where I was using :

    @Html.DropDownListFor(model => model.PersonId, new SelectList(ViewBag.Id, "Value", "Text"),"---Select---")
    i've tried:

    @Html.TextBoxFor(model =>model.currentPersonID, "currentPersonID")

    //and

    @Html.LabelFor(model =>model.currentPersonID)

    hoping the correct ID would display, but only the text 'currentPersonID is displayed please advise, thanks again

    ASP.NET database debugging question announcement

  • [session] returns null
    X xnaLearner

    opps, thanks for that feeling tired this morning and missed that.

    Anyway i've made an edit to the Q if you can see my original post that would be great Thanks

    ASP.NET database debugging question announcement

  • [session] returns null
    X xnaLearner

    Im using a session variable to pass the user ID from the Index to the Create in the HomeController. ATM the user can use a drop down to select their name from the list of users and click 'View' to list the holidays they have previously booked. From there the user can click 'create' which will bring the user to a page which enables them to create a new holiday. From here they have to select their name again from the drop down list. I want to store the users ID from the previous drop down so it will update automatically if they try to create another holiday (to replace the second drop down) Im using a session variable to do this, iv put Session["userameID"] = currentID; in my view. Iv break pointed it just after and if I hold my mouse over 'currentID' it displays the correct ID of the user. So iv tried to pass this down to the create method using string xx = (string)Session["usernameID"]; However string 'xx' is returning NULL,., (tested with breakpoint) I then placed the entire session in the view Session["userameID"] = HolidayDate; string xx = (string)Session["usernameID"]; and string 'xx' is still returning null. Is it not meant to return the userID??? Thanks for any replys

    ASP.NET database debugging question announcement

  • session variable / temp data
    X xnaLearner

    So on the users page the user can use a drop down to select their name and then click 'view' to view the list of holidays they have previously booked. From here they can choose 'select new' which will allow the user to create a new holiday. This all works fine however I want the username to be stored from the original drop down and displayed in the creating page. Instead of having 2 seperate drop downs on each page. I have tried: My first drop down in my Index.chtml

    @Html.DropDownListFor(model => model.HList4DD.First().HolidayDate, new SelectList(Model.PList4DD, "Id", "Name", Model.currentPersonID), "--select--")

    My second drop Down on the create view:

    @Html.DropDownListFor(model => model.PersonId, new SelectList(ViewBag.Id, "Value", "Text"),"---Select---")

    ----------------------- I wanted to change this to the name of the user previously selected so in my get of the Index I have used:

    TempData["CurrentPersonID"] =currentPersonID;

    Then to replace my second drop down im trying something like:

    @TempData["CurrentPersonID"]

    @Html.LabelFor(model => model.currentPersonID, "currentPersonID")
    @Html.ValidationMessageFor(model => model.PersonId)

    Any suggestions? Thanks

    ASP.NET html database question

  • Can only book for yourself and not other users?
    X xnaLearner

    At the min, any user can book a holiday for ay employee, I have added [Authorization] to the controllers, and @if (User.Identity.IsAuthenticated) in the layout so only logged in users can view the pages. But how can I go about only allowing users to book a holiday for them selves something like if loggedInUserID(is this assigned automatically when a user is created?) =currentPersoID, although this is only a guess and I would prob have to assign the same loggedInUserID to personID. any suggestions? Thanks

    ASP.NET question security learning

  • Can only book for yourself and not other users?
    X xnaLearner

    At the min, any user can book a holiday for ay employee, I have added [Authorization] to the controllers, and @if (User.Identity.IsAuthenticated) in the layout so only logged in users can view the pages. But how can I go about only allowing users to book a holiday for them selves something like if loggedInUserID(is this assigned automatically when a user is created?) =currentPersoID, although this is only a guess and I would prob have to assign the same loggedInUserID to personID. any suggestions? Thanks

    .NET (Core and Framework) question security learning

  • using [Authorize] mvc3
    X xnaLearner

    ok thanks

    .NET (Core and Framework) question html database

  • using [Authorize] mvc3
    X xnaLearner

    So at the top of my controllers i've added in [Authorize], So far so good only logged in users can access these pages (Person and Holiday) However the tabs in the homeController which navigate the users to these pages are still displayed...coming from the layout.cs

      *   @Html.ActionLink("Home", "Index", "Home")
            *   @Html.ActionLink("About", "About", "Home")
            *   @Html.ActionLink("Person", "Index", "Person")
            *   @Html.ActionLink("Holidays", "Index", "Holidays")
    

    How can I only get these tabs to display if a user is logged in. I have tried the approach of adding in a bool in the AccountController.cs

    else
    {
    loggedIn = true;
    return RedirectToAction("Index", "Home");
    }
    }
    else
    {
    loggedIn = false;
    ModelState.AddModelError("", "The user name or password provided is incorrect.");
    }

    but then how do I access this from the layout.cs? Is this the correct approach. Please advise. thanks

    .NET (Core and Framework) question html database

  • pulling across value from list to display in view
    X xnaLearner

    Yeah that worked thanks for the help frazzle

    .NET (Core and Framework) html asp-net database architecture question

  • pulling across value from list to display in view
    X xnaLearner

    Im now using

    bool isFirst = true;
    @int remainingHolidays = 0;

    @foreach (var item in Model.HList4DD)
    {

            @Html.DisplayFor(modelItem => item.PersonId)
        
        
            @Html.DisplayFor(modelItem => item.HolidayDate)
    

    if (isFirst)
    {
    remainingHolidays = item.Person.HolidaysRemaining;
    isFirst = false;
    }

            @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
            @Html.ActionLink("Details", "Details", new { id = item.Id }) |
            @Html.ActionLink("Delete", "Delete", new { id = item.Id })
        
    }
        
    
    
      
    
         @\*   @Html.LabelFor(model => model.PList4DD, "Person")\*@
        
    
        
    
       
             <form action ="/Holidays/Index" id="some" method="post"> 
    
            @\* \*WORKING VERSION\*\*@ @Html.DropDownListFor(model => model.HList4DD.First().HolidayDate, new SelectList(Model.PList4DD, "Id", "Name", Model.currentPersonID), "--select--")
        
    
       <script>
           function updateFormEnabled() 
           {
               if (verifyAdSettings()) 
               {
                   $('#sbmt').removeAttr('disabled');
               }
               else 
               {
                   $('#sbmt').attr('disabled', 'disabled');
               }
           }
    
           function verifyAdSettings() 
           {
               if ($('#HolidayDate').val() != '') 
               {
                   return true;
    
               }
               else 
               {
                   return false;
               }
           }
    
    
           $('#HolidayDate').change(updateFormEnabled);         
           </script>
    
      
      @remainingHolidays.ToString()
    
               
             <input type="submit" id= "sbmt" name="ViewHolidaysDD" value="View"/>
              </form>
    

    <script>
    $('#sbmt').attr('disabled', '');
    </script>

    the @remainingHolidays.ToString() 5 lines or so up from the bottom is saying it doesnt exist in the current context?

    .NET (Core and Framework) html asp-net database architecture question

  • pulling across value from list to display in view
    X xnaLearner

    Hey Guys...so trying to get my head around MVC My Index for holiday page is linked to the model

    @model HolidayBookingApp.Models.HolidayList

    Im trying to pull the value of Holidays remaining from the HList4DD (HolidayListForDropDown) which is coming from the HolidayList.cs page. I can get it through...

    @foreach (var item in Model.HList4DD)
    {

            @Html.DisplayFor(modelItem => item.PersonId)
        
        
            @Html.DisplayFor(modelItem => item.HolidayDate)
        
        
        @Html.DisplayFor(modelItem => item.Person.HolidaysRemaining)
    

    Although this displays the holidays remaining for every holiday booked. So if 20 holidays is the limit (4 booked and 16 remaining) this will produce a list of the dates of holidays booked i.e 4 records stating which date is booked, but it will show the '16' holidays remaining 4 times as well. Yes, this is because it is inside the for loop but I tried to display it on its own and it didnt work

    @Html.DisplayFor(model => model.HList4DD.//what do i add here?

    Also tried to add

    Person person = new Person();
    currentHolidaysRemaining = person.HolidaysRemaining;

    to the HolidayList. cs then in the view do

    @Html.DisplayFor(model => model.currentHolidaysRemaining)

    but its not pulling across the correct value, just returning 0 please advise....thanks

    .NET (Core and Framework) html asp-net database architecture question
  • Login

  • Don't have an account? Register

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