0

I have a ToDo items dashboard page where I display the ToDo's, their status and some other app info. I want to have one input where I can add a string value (the ToDo title) and on the button click have that passed to the controllers Create get method, so it populates the Create views Title input field with that value.

I want to it without a form if that is possible as the dashboard page already has a model which is an IEnumerable, just pass that value as a querystring parameter to the Create pages get view (or is it doable in javascript?).

Im not an MVC expert and also not as familiar with the new tag helper methodologies. Any help in how to structure thiswould be helpful.

Here is the html

 <!-- Add Task -->
  <div class="input-group input-group-lg">
     <input class="form-control" type="text" placeholder="Add task and press enter..">
     <span class="input-group-addon">
        <a asp-controller="ToDoItems" asp-action="Create" ><i class="fa fa-plus"></i></a>
     </span>
  </div>
 <!-- END Add task -->
2
  • put it in a form and change the model into a new one that holds the IEnumerable property and the string property Commented Oct 23, 2019 at 18:46
  • @Train and pass the whole thing? I want to just send the string, is that possible? Commented Oct 23, 2019 at 19:17

1 Answer 1

1

here is the new model

public Class MyModel{
    public IEnumerable<your old model> Old Model {get; set;}
    public string Title {get;set;}
}

You can create a form like so in html with razor syntax

    @model MyModel
...
        <form action="/Controller/PostTitle/" method="post">
             @Html.TextBoxFor(m => m.Title,new {@class = "...", @placeholder="...", 
             @requried="required"})
            <input id="export-btn" type="submit" value="Download" class="btn btn-info" />
        </form>

The @TextBoxFor will create a textbox and the lambda lets you use your strongly typed model.

Here is the controller

 [HttpPost]
        public IActionResult PostTitle(string Title) {

           ...
        }
Sign up to request clarification or add additional context in comments.

2 Comments

@Train...your example, though not the route I went (Other than changing the model), got me to figure out how to do it
Glad it helped out, sorry it wasn't the correct solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.