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 7725351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:54:57+00:00 2026-06-01T04:54:57+00:00

NOTE: Edited to add the Model The Problem: a querystring guid value is giving

  • 0

NOTE: Edited to add the Model

The Problem: a querystring guid value is giving me fits, trying to get it into my controller so I can Create a new record with it as a parameter. The closest that I’ve gotten so far loads a record with all 0’s and dashes for the guid (which is not only wrong but looks very weird.)

This is in MVC3/EF4 with a legacy database and some legacy pages and URLs. The application that I’m working on includes a note-taking functionality, where User A can makes notes about User B (for example.) Both users have their own guid Ids that identify them, and the table where the notes are stored has an Id column for the note itself and then two Id columns to keep track of which is User A and which is User B for this particular note.

We can always assume that User A is the current User, and get his Id that way. One of the legacy URLs is how you get the Id for User B.

For example: http://www.mysite.com/notes/user/ED88B0B1-B552-4D63-BD20-C94B837440BE

“User A” in our example has the guid of ScannerUserId

“User B” (from the querystring) has the guid of ScannedCodeId

Here is the model:

public partial class Note
{
    public System.Guid ScannerUserId { get; set; }
    public System.Guid ScannedCodeId { get; set; }
    public System.Guid NoteId { get; set; }
    public string NoteDetail { get; set; }

    public virtual Code Code { get; set; }
    public virtual Contact Contact { get; set; }
}

Here is the view:

@model MySite.Models.Note

@{
ViewBag.Title = "Create";
}

<h2>Create</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
    <legend>Note</legend>

    <div class="editor-label">
        @Html.LabelFor(model => model.NoteDetail)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.NoteDetail)
        @Html.ValidationMessageFor(model => model.NoteDetail)
    </div>
    <p>
        <input type="submit" value="Create" />
    </p>
</fieldset>
}

And here is the controller section on Create:

public class NoteController : Controller
{
    //
    // GET: /Note/Create

    public ActionResult Create()
    {
        ViewBag.ScannedCodeId = new SelectList(db.Codes, "CodeId", "ScannedCodeId");
        ViewBag.ScannerUserId = new SelectList(db.Contacts, "UserId", "ScannerUserId");
        return View();
    } 
    //
    // POST: /Note/Create

    [HttpPost]
    public ActionResult Create(Note note)
    {
        if (ModelState.IsValid)
        {
            note.NoteId = Guid.NewGuid();
            note.ScannerUserId = (Guid)System.Web.Security.Membership.GetUser().ProviderUserKey;
            //note.ScannedCodeId = new Guid(Request.QueryString[""]);
            note.CreateDate = DateTime.Now;
            note.LastActivityDate = DateTime.Now;
            db.Notes.Add(note);
            db.SaveChanges();
            return RedirectToAction("Index");  
        }

        ViewBag.ScannedCodeId = new SelectList(db.Codes, "CodeId", "ScannedCodeId", note.ScannedCodeId);
        ViewBag.ScannerUserId = new SelectList(db.Contacts, "UserId", "ScannerUserId", note.ScannerUserId);
        return View(note);
    }

How do I get the guid that is in the querystring into the note.ScannedCodeId such that the db.SaveChanges will not blow up on me?

And also, thank you for reading this far and anything you can do to help.

  • 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-06-01T04:54:58+00:00Added an answer on June 1, 2026 at 4:54 am

    I believe Note is your ViewModel.Add a WrittenFor property to that

    (I am using Int datatype in this example to keep this answer simple and much readable. you can replace it with the string for your unique id/guid)

    public class Note
    {
      public string NoteDescr { set;get;}
      public int WrittenBy { set;get;}
      public int WrittenFor { set;get;}
    
    }
    

    and in your get action method return this view model to your view

    [HttpGet]
    public ActionResult Create(int friendId)
        {
            Note objVm=new Note();
            objVm.WrittenFor=friendId;
            return View(objVm);
        } 
    

    So the user can access this page by browsing like

    http://yourdomain/yourcontroller/create/589476
    

    That means you (The current use is in the wall (or note book..:) ) of user with id 589476.

    and in your View, Have it in the form using @Html.HiddenFor HTml helper method. Then when you submit your form, you will get it in your viewmode which is a parameter of your HttpPost Create method

    @model Note
    
    @using (Html.BeginForm())
    {   
      @Html.TextBoxFor(m=>m.NotDesc)
      @Html.HiddenFor(m => m.WrittenFor)
      <input type="submit" value="Create" />
    }
    

    and in your HttpPost action method, you have what you want

    [HttpGet]
    public ActionResult Create(Note objNote)
    {
       int friendId= objNote.WrittenFor 
       string note=objNote.NoteDesc
       //Now you can save your value 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NOTE: EDITED The real-world situation is a series of events that each have two
Note: I edited this question to make it easier for other people with the
I've come across a weird problem which I can't solve, no matter what i
Edited: Please note, when I mention performance comparison, it is not performance comparison of
Note: Edited based on responses to receive more appropriate answers. I have a collection
Edit: I've edited the sample to better resemble the problem I have, now the
Please note, sarnold has heavily edited the question; the original question, in its entirety,
EDITED I'm trying to have source files recompiled without having to specify header files
Note: question has been edited to stay in sync with what I have tried
Note: this was inspired by WebBrowser Event Properties? Why am I able to access

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.