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

  • Home
  • SEARCH
  • 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 8605621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:52:56+00:00 2026-06-12T02:52:56+00:00

I’m using MVC 4 and usually Visual Studio will create all the views for

  • 0

I’m using MVC 4 and usually Visual Studio will create all the views for you. I have one form that just has one field and I want to just embed the create form into the Index View.

So the Index View has something like @model IEnumerable<Models.LinkModel>

So I access it by iterating through the Model collection.

But if I try to embed the form for the create action I need @model Models.LinkModel
and it is accessed by Model.Name as well. Is there a way to do this or use a different variable name?

Ok here is some extra info.

SO I have a model.

public class LinkModel
{
   public string LinkUrl {get;set;}
}

I have a controller that has the Create and Index ActionResults.

Now in the Index view I have

@model IEnumerable<Models.LinkModel>

@{
    ViewBag.Title = "Links";
}

I can do all my fancy logic to list all the links.

@foreach(link in Model)
{
    <p>link.LinkUrl<p>
}

The Create View has this

@model Models.LinkModel // Note that it is just one item not IEnumerable

@{
    ViewBag.Title = "Add Link";
}

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <fieldset class="editor-fieldset">
        <legend>LinkModel</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.LinkUrl)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.LinkUrl)
        </div>
       <p>
        <input type="submit" value="Add Link" />
       </p>
    </fieldset>
}

Now it seems pretty stupid to have a create form for just one field. I want to put this form on the Index page. Problem is that I access the object using the variable Model. I wanted to know if there is a way to have two seperate instances or be able to access the Model objects with different names.

  • 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-12T02:52:58+00:00Added an answer on June 12, 2026 at 2:52 am

    Have a composite model with a list of items and 1 single item for the create

    public class  IndexModel {
       public LinkModel CreateModel {get; set;}
       public IEnumerable<LinkModel> Items {get; set;}
    }
    
    
    @model IndexModel
    @using(Html.BeginForm("create")) {
       @Html.EditorFor(m => m.CreateModel.Name);
    }
    @foreach(var item in Model.Items) {
      @item.Name
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to

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.